我有几个虚拟主机监听端口80,一个监听8080.他们有不同的主机名。
当连接到端口8080时,nginx提供301端口,并redirect到端口80上的相同主机名。这似乎来自正确的虚拟主机,因为301出现在所需目标的访问日志中。
任何想法,为什么会发生?
服务器块有快速的cgi和一些重写如下(并在端口80上工作100%)
server { listen 8080; server_name myhost.local; root /path/to/httpdocs; access_log /path/to/log/access.log main; error_log /path/to/log/error.log warn; location / { index index.php; # rewrite clean URLs for wordpress if (-e $request_filename) { break; } rewrite ^/(.+)$ /index.php?q=$1 last; } # Process PHP files with fastcgi location ~ \.php$ { if ( !-f $request_filename ) { return 404; } include /etc/nginx/conf/php-fastcgi.conf; fastcgi_pass 127.0.0.1:8890; fastcgi_index index.php; } }
有一个叫做port_in_redirect的nginx核心模块指令,你可能需要设置为'off'来避免这种情况。
像这样:
location ~ \.php$ { if ( !-f $request_filename ) { return 404; } include /etc/nginx/conf/php-fastcgi.conf; fastcgi_pass 127.0.0.1:8890; fastcgi_index index.php; port_in_redirect off; }
那应该解决问题。
我有你的同样的问题。 我想在同一个域和服务器上有两个wordpress istances,但是在不同的端口上。 WordPress的确是redirect到默认端口(80或443的SSL)。 我通过转到WordPress的pipe理面板解决了它,并在“常规”下将http://example.com更改为http://example.com:xx “其中xx是您希望该实例的Wordpress听的端口。
我认为这是Wordpress安装在PHP级别强制redirect。