cat /etc/nginx/nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
这是我的默认配置文件,如果我没记错的话应该是没做过任何修改的。请确保里面有include /etc/nginx/conf.d/*.conf;这行
这行的意思就是包含了所有/etc/nginx/conf.d/下 后缀是.conf的配置文件
然后我们在/etc/nginx/conf.d/目录下创建test.conf
vi /etc/nginx/conf.d/test.conf server{ listen 80 ; #监听80端口 access_log /var/log/nginx/access.log; #日志文件位置 error_log /var/log/nginx/error.log; location / {#访问/时 include uwsgi_params; #加载uwsgi模块 proxy_pass http://192.168.1.1:8000; #将连接转到该IP } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /static/ { alias /project/static/; #访问/static时直接访问到/project/static } }
然后就大功告成了。当用户直接访问192.168.1.1:80 时 nginx 就会把连接转到192.168.1.1:8000上。
如果文章内有出错的地方,或者对文章有任何意见,可在评论下说明。
更多参考
Nginx+uWSGI+Supervisor在Ubuntu上部署Flask应用
uWSGI+Django+Nginx的工作原理流程与部署过程
Nginx+uWSGI+Django+Python 应用架构部署
Ubuntu Server 14.04.2 LTS 配置 Nginx + Uwsgi + Django