【发布时间】:2019-07-01 21:51:19
【问题描述】:
如何配置 ngnix 以将 proxypass 从具有子文件夹的域重定向到 /?
示例:
https://example.com/yoursub/
到
没有 /yoursub/ 前缀的本地主机
目前从内网直接访问服务器iphttp://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;
}
}
如果相关:后端是带有 gunicorn 服务器的 django 应用程序。
我是否需要考虑从 https 到 http 的重定向?
我无法控制基本域。
【问题讨论】:
标签: django nginx webserver proxypass