nginx+uwsgi

yum install nginx

安装服务实现自启动

建立服务文件

vim /lib/systemd/system/nginx.service

输入以下内容

[Unit]

Description=nginx

After=network.target

[Service]

Type=forking

ExecStart=/usr/sbin/nginx                      #which nginx 去查目录

ExecReload=/usr/sbin/nginx -s reload

ExecStop=/usr/sbin/nginx -s stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

为服务文件设置权限

chmod 754 /lib/systemd/system/nginx.service

设置开机自启动

systemctl start nginx.service
systemctl enable nginx.service

//查看错误的详情

systemctl status nginx.service -l

三、解决方案

1、查看此时占用80端口的程序

netstat -ntlp | grep 80
image

这里可以看到,80端口是被占用的 。我们再详细看看占用80的是什么

ps -ef | grep 80

然后找到pid,杀掉这些程序

//-s9代表的是快速强制的杀掉pid程序

kill- s 9 pid

2、杀到没有程序可杀为止,然后启动nginx

service nginx restart  # nginx重启
service nginx start    # 启动
service nginx stop    # 停止
image

此时启动成功。

启动:

uwsgi --ini xxx.ini

重启:

uwsgi --reload xxx.pid

停止:

uwsgi --stop xxx.pid

uwsgi配置文件

[uwsgi]
chdir=/home/vancouver
module=vancouver.wsgi
# the virtualenv (full path)
virtualenv  = /root/.pyenv/versions/vancouver

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 3
# the socket (use the full path to be safe
socket          = 127.0.0.1:8001
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum          = true

chmod-socket = 666

pidfile = /var/run/vancouver.pid
socket = /var/run/vancouver.sock
pidfile=uwsgi.pid
daemonize = /tmp/vancouver.log                           

nginx配置文件

#root;
#tream component nginx needs to connect to
#upstream django {
#  # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
#  server 127.0.0.1:8000 weight=10; # for a web port socket (we'll use this first)
#}
# configuration of the server
server {
    listen 80;
    server_name sj.czking.top;

    rewrite ^(.*) https://$server_name$1 permanent;
}
server {
  # the port your site will be served on
  listen     443;
  server_tokens off;
  # the domain name it will serve for

  server_name sj.czking.top;

  ssl on;
  charset     utf-8;

  ssl_certificate /home/authorization/1673044_sj.czking.top.pem;
  ssl_certificate_key /home/authorization/1673044_sj.czking.top.key;
  ssl_session_timeout 5m;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;

  # max upload size
  client_max_body_size 200M;   # adjust to taste
  deny 47.101.50.252;
  # Django media

  location /media  {
    alias /home/shop/media;   # 指向django的media目录
  }

  location /static {
    alias /home/shop/static;  # 指向django的static目录
  }

  # Finally, send all non-media requests to the Django server.
  location / {
    include uwsgi_params;
   # uwsgi_pass unix:///var/run/shop.sock;
    uwsgi_pass 127.0.0.1:8001;
  #  proxy_pass http://127.0.0.1:8001;
 #   proxy_pass_request_headers              on;
  }
}

nginx 检查配置文件是否正确

nginx -t 

你可能感兴趣的:(nginx+uwsgi)