一:安装nginx1:安装编译工具和库文件yum-yinstallmakezlibzlib-develgcc-c++libtoolopensslopenssl-devel2:安装PCREwgethttps://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gztarzxvfpcre-8.35.tar.gzcdpcre-8.35./configure--prefix=/usr/local/pcremake&&makeinstall3:安装nginxcd~wgethttps://nginx.org/download/nginx-1.5.6.tar.gztar-zxfnginx-1.5.6.tar.gzcdnginx-1.5.6./configure--prefix=/usr/local/nginx\--with-http_stub_status_module\--with-http_gzip_static_module制作&&makeinstall4判断nginx是否安装成功/usr/local/nginx/sbin/nginx-v2:installuwsgi1:installuwsgipinstalluwsgi(pip3使用:pip3installuwsgi)2:判断uwsgi是否安装成功uwsgi--版本三:Nginx+uwsgi部署Django项目一:uwsgi配置vimtest.initest.ini文件如下:#uwsig使用配置文件启动[uwsgi]socket=127.0.0.1:9090master=true#启用主processvhost=true#多站点模式#启动uwsgi用户名和用户组uid=rootgid=root#指定静态文件static-map=/static=/data/www/test/staticno-site=true#不设置入口多站点模式下的模块和文件工作者=2#子进程数reload-mercy=10vacuum=true#exit,重启时清理文件max-requests=1000limit-as=512buffer-size=30000pidfile=/data/www/script/test.pid#pid文件,用于下面脚本启动和停止进程daemonize=/data/www/script/test.log#日志文件pythonpath=/usr/local/lib/python3.6/site-packages#Python环境地址2:nginx配置服务器{listen80;服务器名称local.test.com;位置/{包括uwsgi_params;uwsgi_pass127.0.0.1:9090;#必须和uwsgi中的设置一致uwsgi_paramUWSGI_SCRIPTtest.wsgi;#入口文件,即wsgi.py相对于项目根目录的位置,“.”相当于一层目录uwsgi_paramUWSGI_CHDIR/data/www/test;#项目根目录indexindex.htmlindex.htm;client_max_body_size35m;}}3:启动服务killall-9nginx#Stopnginxkillall-9uwsgi#Stopuwsgiuwsgi--ini/data/www/script/test.ini#Startuwsgiscript/usr/local/nginx/sbin/nginx#Startnginx4:判断是否配置成功,在浏览器中访问local.test.com。如果访问不正常,可能是防火墙问题。解决:#打开指定端口/sbin/iptables-IINPUT-ptcp--dport80-jACCEPT/etc/rc.d/init.d/iptablessave#保存配置/etc/rc.d/init.d/iptablesrestart#重启服务#关闭防火墙ystemctlstopfirewalld.service#关闭防火墙systemctldisablefirewalld.service#开机时关闭防火墙
