Nginx port_in_redirect不起作用?

前端之家收集整理的这篇文章主要介绍了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/*;
}

NginxNginx版本:Nginx / 1.0.9

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

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

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

原文链接:/nginx/532209.html

猜你在找的Nginx相关文章