Removing a port from nginx redirect

I had a problem where some redirects on a website included a proxy pass port, making them useless. My configuration is as follows:

Physical server 1:

server { server_name example.com www.example.com; location / { proxy_pass http://1.1.1.1:50493; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host "example.com"; } } 

Physical server 2:

 server { listen 50493; server_name example.com www.example.com; set_real_ip_from 1.1.1.1; root /var/www/example.com; index index.php index.htm index.html; location / { if ($http_host !~ "^example.com"){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ rewrite ^/(.*) http://example.com/$1 permanent; } rewrite /[^/]+/([0-9]+)-[^/]+.html http://example.com/showthread.php?t=$1 permanent; } location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/example.com$fastcgi_script_name; include fastcgi_params; fastcgi_read_timeout 600s; fastcgi_buffer_size 512k; fastcgi_buffers 16 512k; } } 

As a rule, viewing works fine. The site is available for viewing, as expected. However, some links that are redirected (for example, after the login action) are redirected to the link with port 50493. Therefore, we get http://example.com:50493/index.php . This will not work. My question is: how to remove a port?

From what I can tell, forum software takes a port from a php session port variable. I tried setting port_in_redirect, but to no avail. If this helps, the problem stands out here: http://kb.parallels.com/en/114425 .

Thanks.

+4
source share
3 answers

He will tell you how to fix your problem in the link you provided. The change:

 <?php echo $VAR->domain->asciiName ?>:<?php echo $OPT['ssl'] ? $VAR->server->webserver->httpsPort : $VAR->server->webserver->httpPort ?>" 

to

 <?php echo $VAR->domain->asciiName ?>" 

You should fix this in your application, not in Nginx.

Your application generates links that point to port 50493 like this . If you are not going to set up a content filter that goes through all the HTML and replaces example.com:50493/path/of/url with example.com/path/of/url , then you should fix it inside the application.

0
source

in your nginx.conf

 http { port_in_redirect off; } 
+5
source

try to substitute on the fly

HttpSubModule

 sub_filter 'example.com:50493/' 'example.com/' ; sub_filter_once off; 

this should do the trick.

0
source

Source: https://habr.com/ru/post/1482477/


All Articles