nginx通过uWSGI在一个子目录中提供Django

前端之家收集整理的这篇文章主要介绍了nginx通过uWSGI在一个子目录中提供Django前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我已经完成了一些以前的主题
How do I set subdirectory in nginx with Django
how to deploy django under a suburl behind nginx
Serving flask app on subdirectory nginx + uwsgi

基本的教训是,您只需要配置您的站点(可用)即可实现此目的.我现在尝试了各种各样的排列

@H_403_10@server { listen 80; server_name www.example.com; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /path/to/project; } location /project/ { root /path/to/project; include /etc/Nginx/uwsgi_params; uwsgi_param SCRIPT_NAME /project; uwsgi_modifier1 30; uwsgi_param PATH_INFO "$1"; uwsgi_pass unix:/tmp/project.sock; }}

当我将位置定义为“/”时,一切都运行得很好(并删除SCRIPT_NAME,modifier1,PATH_INFO和root并不重要.但是尝试使用子目录总是会导致找不到页面(404):

@H_403_10@Request URL: http://www.example.com/project/project

(编辑)它正在为请求添加目录.我怎么不搞清楚?

(尝试过forced_script_name – 不应该使用它并给出其他类型的头痛 – 和uwsgi配置设置)

编辑:

@H_403_10@location /project/ { root /path/to/project; include /etc/Nginx/uwsgi_params; uwsgi_param SCRIPT_NAME /project; uwsgi_pass unix:/tmp/project.sock; }

不起作用…套接字在那里,当我配置/时工作 – 我只是看不到我错过的东西.

更新:

@H_403_10@location ~ /project(?Nginx/uwsgi_params; uwsgi_pass unix:/tmp/project.sock; uwsgi_param PATH_INFO $path_info; uwsgi_param SCRIPT_NAME /project; }

这会加载网站,但所有链接都指向http://example.com/link/to/something而不是http://example.com/project/link/to/something

最佳答案
在uWSGI中不推荐使用Nginx uwsgi_modifier1.

您的目标是能够从任何地方托管wsgi应用程序,而无需对应用程序进行调整以考虑其所在的位置.

在uWSGI中执行此操作的当前方法是为每个URI应用程序组合映射挂载点,如下所示:

@H_403_10@[uwsgi] socket = 127.0.0.1:3031 ; mount apps mount = /app1=app1.py mount = /app2=app2.py ; rewrite SCRIPT_NAME and PATH_INFO accordingly manage-script-name = true

Hosting multiple apps in the same process (aka managing SCRIPT_NAME and PATH_INFO)

mount可以取代模块

特别是Django,

@H_403_10@; Before module = django_app.wsgi:application ; After mount = /django_app=django_app.wsgi:application manage-script-name = true

猜你在找的Nginx相关文章