Nginx从80重定向到8080

时间:2014-03-03 08:46:08

标签: redirect nginx

我使用的是nginx作为负载均衡器,但是有一个让我感到困惑的问题。 我的nginx.conf:

upstream backend {
    ip_hash;
    server 172.16.117.200:8080 weight=1;
    server 172.16.117.201:8080 weight=4;
}
server {
    location / {
        listen       80;
        index  index.php index.html index.htm;
        proxy_pass http://backend;
    }
}
server {
    listen       8080;
    server_name  localhost;
    root   /var/www;
    location /aa {
        if ($request_uri ~* ^.*/.*$) {
            rewrite ^/(mp)/(.*)$  /$1/index.php?q=$2 last;
            break;
        }
    }
}

当我在浏览器中输入172.16.1.200/aa/时,一切正常,但如果我在浏览器中输入172.16.117.200/aa(不带斜线),则地址将重定向到http://172.16.117.200:8080/aa/

有什么问题?

1 个答案:

答案 0 :(得分:-1)

如果文件不是0644不正确或文件未找到将重定向与真实端口确保它找到和神0644有时它不是自动索引或你没有设置索引在nginx.conf使重定向到index.php尝试使用172.16。 1.200 / AA / index.php的

进入blancer

upstream backend {
    ip_hash;
    server 172.16.117.200:8080 weight=1;
    server 172.16.117.201:8080 weight=4;
}
server {
    server_name  localhost;

    location / {
        listen       80;
        index  index.php index.html index.htm;
        proxy_pass http://backend;
    }
}

进入172.16.117.200 nginx.conf

server {
    server_name  172.16.117.200;
            rewrite ^/(mp)/(.*)$  /$1/index.php?q=$2 last;

    location / {
        listen       *:8080;
        index  index.php index.html index.htm;
root  /aa;
    }
}
相关问题