Gur*_*nig 6 django webserver nginx proxypass
如何配置ngnix将proxypass从具有子文件夹的域重定向到/?
示例:
https:
//example.com/yoursub/ to localhost without/yoursub/prefix
目前,从Intranet 直接访问服务器ip http://xxx.xxx.xxx.xx/可以正常工作.
我的nginx配置文件:
upstream app_server {
server unix:/home/myname/APP-Server/gunicorn/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
# add here the ip address of your server
# or a domain pointing to that ip (like example.com or www.example.com)
server_name 123.456.789.1;
keepalive_timeout 5;
client_max_body_size 4G;
access_log /home/myname/APP-Server/logs/nginx-access.log;
error_log /home/myname/APP-Server/logs/nginx-error.log;
location /static/ {
alias /home/myname/APP-Server/static-root/;
}
# checks for static file, if not found proxy to app
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
Run Code Online (Sandbox Code Playgroud)
如果它是相关的:后端是一个带有gunicorn服务器的django应用程序.
我是否必须考虑从https到http的重定向?
我无法控制基域.
尝试这个:
server {
...
location @proxy_to_app {
...
proxy_pass http://app_server/; # note the trailing slash
}
}
Run Code Online (Sandbox Code Playgroud)
解释
根据nginx 文档:
如果使用 URI 指定 proxy_pass 指令,则当请求传递到服务器时,规范化请求 URI 中与位置匹配的部分将被指令中指定的 URI 替换。
由于位置与任何内容匹配,因此在代理到上游之前,/所有内容都将被/( 中的尾部斜杠)替换。proxy_pass
| 归档时间: |
|
| 查看次数: |
790 次 |
| 最近记录: |