本站教程收集整理的这篇文章主要介绍了Ubuntu16.04 nginx+uwsgi二级目录,本站教程本站觉得挺不错的,现在分享给大家,也给大家做个参考。
笔者在同一台服务器上部署了django和php,为了使两者共存而想到了将django项目部署到二级目录下,而Nginx则使用的反向代理
django中uwsgi的配置文件
[uwsgi] chdir = /var/www/html/api module = api.wsgi master = true processes = 10 #socket = :8080 http = :8080 VACUUM = true pidfile = /tmp/uwsgi.pid
Nginx默认是将用户的请求通过socket与django通信,如果使用了Nginx的反向代理之后访问则会通过http与django通信,所以上面的配置文件中需要将socket注释掉,取而代之的则是http = :8080。
主要需要修改的是Nginx的配置文件
upstream django { server 127.0.0.1:8080; } server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm index.Nginx-debian.html; server_name _; LOCATIOn / { try_files $uri $uri/ =404; } LOCATIOn /api { # 这里为django项目的配置内容 uwsgi_pass django; proxy_pass http://django/api; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-ForWARDed-For $proxy_add_x_forWARDed_for; include /var/www/html/api/uwsgi_params; } LOCATIOn ^~ /api/static { alias /var/www/html/bill/static; } LOCATIOn ~ \.php$ { include fastcgi.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; }
在浏览器中则可以使用http://服务器IP/api/,访问到django项目
便宜香港vps
本站总结
以上是本站教程为你收集整理的Ubuntu16.04 nginx+uwsgi二级目录全部内容,希望文章能够帮你解决Ubuntu16.04 nginx+uwsgi二级目录所遇到的程序开发问题。
如果觉得本站教程网站内容还不错,欢迎将本站教程推荐给好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。