具有特定端口的nginx上的多个应用程序

时间:2022-02-19 18:12:57

I'm tring to make many django/gunicorn app on one server. Each app listen on one specific port. My nginx conf is like :

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

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;
           }
}

This conf work for GET request (when i acces to example.com:2318/my-url), but any POST request (submit form) redirect me on 80 port (example.com/my-new-url).

这个配合适用于GET请求(当我访问example.com:2318/my-url时),但任何POST请求(提交表单)都将我重定向到80端口(example.com/my-new-url)。

What's wrong with my conf ?

我的conf有什么问题?

Thanks

谢谢

1 个解决方案

#1


1  

I have solution. The problem was in the header location.

我有解决方案。问题出在标题位置。

I had need to use proxy_redirect header like this.

我需要像这样使用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;
       }
}

#1


1  

I have solution. The problem was in the header location.

我有解决方案。问题出在标题位置。

I had need to use proxy_redirect header like this.

我需要像这样使用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;
       }
}