【问题标题】:Multiple app on nginx with specific port具有特定端口的 nginx 上的多个应用程序
【发布时间】:2015-05-11 15:56:31
【问题描述】:

我想在一台服务器上制作许多 django/gunicorn 应用程序。每个应用程序都侦听一个特定的端口。我的 nginx 配置是这样的:

upstream my_app_2318 {
       server unix:/tmp/gunicorn-2318.sock    fail_timeout=10s
}
       server {
           listen                *:2318;
           server_name           example.com;

           index  index.html index.htm index.php;

           access_log            /opt/2318/logs/nginx_access.log combined;
           error_log             /opt/2318/logs/nginx_error.log;

           location / {
               proxy_pass            http://my_app_2318;
               proxy_read_timeout    90;
               proxy_connect_timeout 90;
               proxy_redirect        off;
           }
}

此配置适用于 GET 请求(当我访问 example.com:2318/my-url 时),但任何 POST 请求(提交表单)将我重定向到 80 端口(@98​​7654323@)。

我的配置有什么问题?

谢谢

【问题讨论】:

  • 因为你写了proxy_redirect off;
  • 当我输入proxy_redirect default; 时,我遇到了同样的问题
  • 检查 Location 标头中的确切内容
  • 检查您的 html 代码,更具体地说,检查您的 form 标记的 action 属性。
  • @AlexeyTen 我该如何检查?

标签: django nginx port gunicorn


【解决方案1】:

我有解决办法。问题出在标题位置。

我需要像这样使用 proxy_redirect 标头。

upstream my_app_2318 {
   server unix:/tmp/gunicorn-2318.sock    fail_timeout=10s
}
   server {
       listen                *:2318;
       server_name           example.com;

       index  index.html index.htm index.php;

       access_log            /opt/2318/logs/nginx_access.log combined;
       error_log             /opt/2318/logs/nginx_error.log;

       location / {
           proxy_pass            http://my_app_2318;
           proxy_redirect        http://example.com/ http://example.com:2318/;
           proxy_read_timeout    90;
           proxy_connect_timeout 90;
       }
}

【讨论】:

    猜你喜欢
    • 2016-03-24
    • 2022-01-07
    • 1970-01-01
    • 2020-10-26
    • 2018-01-12
    • 2011-10-24
    • 2012-06-26
    • 2021-03-05
    • 2019-08-07
    相关资源
    最近更新 更多