uwsgi和nginx的配置

本文介绍了在配置uwsgi和nginx时需要注意的事项,特别是uwsgi对python版本的要求,以及配置ini文件时不能使用#注释与参数在同一行的细节。同时提及nginx配置文件在负载均衡设置上的应用,但未深入探讨。最后提到了django的使用,以及如何通过ini文件让uwsgi在后台成功运行。

uwsgi需要python的支持,所以版本很重要,安装的时候就要注意python版本,或是pip3(python3)

后续再修改就需要先卸载再安装。。。。。。。

安装 uwsgi

python -m pip install uwsgi#注意python的版本
pip install uwsgi#

在配置ini文件中犯了个莫名奇妙的问题,使用了#注释,然后一直报错,然后发现不能和和设置的参数在同一行,要换行,真是简直了...

配置ini文件,一般放在主项目内。

# mysite_uwsgi.ini file
[uwsgi]
#pythonpath和plugin  只需要一种
pythonpath = /usr/local/lib/python3.9/site-packages
#!/bin/sh
http-socket     =:8000 
#plugin          =python3.9
module          = topic.wsgi:application
daemonize       = /var/log/uwsgi.log

chdir           = /root/opj/topic/
wsgi-file=/root/opj/topic/wsgi.py

master          = True
# maximum number of worker processes
processes       = 4

# clear environment on exit
vacuum          = True

# python 文件修改后自动重启,并没有实现。。。
py-autoreload = 1

# uwsig pid 号
pidfile = /root/opj/topic/topic_uwsgi.pid
# 重启的时候使用的 pid 号
touch-reload = /root/opj/topic/topic_uwsgi.pid


nginx:/etc/nginx/nginx.conf;这里使用了负载均衡的写法,并没有搞清楚。。。

worker_processes 1;

user root;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
error_log  /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;




events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # set to 'on' if nginx worker_processes > 1
}

http {
  include mime.types;
  # fallback in case we can't determine a type
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log combined;
  sendfile on;

  upstream app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # for UNIX domain socket setups

    #server unix:/root/opj/topic/topic.sock fail_timeout=0;
    server 1.12.230.35:8000;
    # for a TCP configuration
    # server 192.168.0.7:8000 fail_timeout=0;
  }

  server {
    # if no Host match, close the connection to prevent host spoofing
    listen 80 default_server;
    return 444;
  }

  server {
    # use 'listen 80 deferred;' for Linux
    # use 'listen 80 accept_filter=httpready;' for FreeBSD
    listen 80;
    client_max_body_size 4G;

    # set the correct host(s) for your site
    #指定域名,空格更多域名
    server_name www.1add10.com;

    keepalive_timeout 5;

    # path for static files
    #root  /root/opt/topic/quest/templates/quest/;

    location / {
    #如果有更多配置,必须在最前。
      proxy_pass http://1.12.230.35:8000;
    }

    location @proxy_to_app {

    }

    error_page 500 502 503 504 /500.html;
  }
}


topic_nginx:后续补充django的使用

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:///root/opj/topic/topic.sock; # for a file socket

}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name www.1add10.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /root/opj/topic/image;  # your Django project's media files - amend as required
    }

    location /static {
        alias /root/opj/topic/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include /root/opj/topic/uwsgi_params; # the uwsgi_params file you installed
    }
}

 

最后在ini文件中执行后台运行成功

ps -ef | grep uwsgi#查询进程
kill -9 PID#关闭uwsgi
uwsgi --ini uwsgi.ini   #执行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值