Nginx port_in_redirect不起作用?

我最近设置了一个Nginx服务器来托管wordpress安装,并使用Varnish作为服务器前面的反向代理. Varnish在端口80上运行,因此我将Nginx设置为侦听80并重定向.不幸的是,在重定向时,端口8080附加到了nginx请求.

包括port_in_redirect off似乎是解决此问题的一般方法,但它似乎不适用于我.我已经在下面附加了/ sites-enabled / default配置.我做错什么了吗? php重定向似乎工作正常,仅在失败的位置/.

/ sites-enabled / default:

server { 
    listen 8080 default;
    server_name "" xxx.xxx.xxx.xxx;  #just using IP here (no domain yet)

    port_in_redirect off;
    server_name_in_redirect off;

    access_log  /var/log/nginx/localhost.access.log;


    location / {
            root   /var/www/site/html/;
            index  index index.php;
            try_files $uri/ $uri /index.php?q=$uri&$args;
    }

    location ~ .php${
            fastcgi_split_path_info ^(.+.php)(.*)$;
            fastcgi_pass   backend;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/site/html/$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_param  QUERY_STRING     $query_string;
            fastcgi_param  REQUEST_METHOD   $request_method;
            fastcgi_param  CONTENT_TYPE     $content_type;
            fastcgi_param  CONTENT_LENGTH   $content_length;
            fastcgi_intercept_errors        on;
            fastcgi_ignore_client_abort     off;
            fastcgi_connect_timeout 60;
            fastcgi_send_timeout 180;
            fastcgi_read_timeout 180;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_param SERVER_PORT 80;
    }

    location ~ /.ht {
        deny  all;
    }
    location ~ /.git {
        deny  all;
    }
    location ~ /.svn {
        deny  all;
    }

}

upstream backend {
    server 127.0.0.1:9000;
}

nginx.conf:

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log debug;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    multi_accept on; 
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush     off;

    keepalive_timeout  30;
    tcp_nodelay        on;

    gzip  on;
    gzip_proxied any;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

nginx:nginx版本:nginx / 1.0.9

最佳答案
实际上,只是对其进行了排序.简单错误-在Wordpress管理网站wp-admin>设置> WordPress地址(URL)和站点地址(URL)在URL中都具有端口8080!因此,重定向.上面的设置可以像这样正常工作.

如果那不能解决您的问题,我学到的一个技巧是添加print_r($_ SERVER [“ SERVER_PORT”]);在index.php中,以确保您从fastcgi设置了正确的端口(在我的情况下为80).

希望这个简单的步骤可以节省一些时间!

转载注明原文:Nginx port_in_redirect不起作用? - 代码日志