V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
fuxkcsdn
V2EX  ›  NGINX

二级域名重定向,设置了 www 重定向到没有 www 的,怎么连其他的二级域名也被重定向了?

  •  
  •   fuxkcsdn · May 16, 2014 · 3560 views
    This topic created in 4376 days ago, the information mentioned may be changed or developed.
    OS Ubuntu 14.04 LTS
    nginx版本1.6.0,配置文件在最底下
    因为是在本地调试(windows 8.1 update),所以在hosts文件里添加了
    192.168.1.10 mydomain.com
    192.168.1.10 www.mydomain.com
    192.168.1.10 test.mydomain.com

    访问 http://mydomain.com/index.php正常
    访问 http://www.mydomain.com/index.php正常重定向到http://mydomain.com/index.php
    访问 http://test.mydomain.com/index.php也被重定向到http://mydomain.com/index.php
    在IE11,watefox 26,Chrome 34上测试都这样
    哪里配置错了吗??
    ====================================
    user nginx nginx;
    master_process off;
    events {
    worker_connections 1024;
    }
    http {
    gzip on;
    sendfile on;
    include mime.types;
    default_type application/octet-stream;
    keepalive_timeout 65;
    server {
    listen 80;
    server_name www.mydomain.com;
    return 301 http://mydomain.com$request_uri
    }
    server {
    root /var/www;
    listen 80;
    server_name mydomain.com;
    location ~* \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    }
    location / {
    index index.html index.htm index.php;
    }
    }
    }
    ====================================
    Supplement 1  ·  May 16, 2014
    FF和CHROME访问http://192.168.1.10/index.php也会被重定向到http://mydomain.com/index.php,而 IE11则不会...

    设置了default_server依然无效...
    server {
    root /var/www;
    listen 80 default_server;
    server_name mydomain.com;
    ....
    }
    Supplement 2  ·  May 16, 2014
    好吧...貌似是系统问题...

    我在虚拟机里用curl和lynx测试都是正常的...只重定向www到mydomain.com,test.mydomain.com并没有被重定向...
    尝试重启WIN 8.1,还是一样...啥都给我重定向....orz
    Supplement 3  ·  May 16, 2014
    好吧,确认是windows 8.1上hosts文件问题
    我把hosts文件里的信息删掉,用路由器的dnsmasq作为本地dns,就正常了...
    你妹啊...怪就怪自己当初没先用curl测试 TAT
    4 replies    2014-05-16 12:19:29 +08:00
    sandtears
        1
    sandtears  
       May 16, 2014
    看你没写 test 的情况, 估计是你把 www.mydomain.com 设成默认了,因为没写 test ,所以采用默认的 www 。

    你试试直接访问 IP 是不是也调到 mydomain.com
    sandtears
        2
    sandtears  
       May 16, 2014
    @sandtears 额。。。 最后一句改成 “跳到 mydomain.com” 最近总是 typo, so sad...
    Ellison
        3
    Ellison  
       May 16, 2014 via Android
    这是被当成默认站点了吧
    fuxkcsdn
        4
    fuxkcsdn  
    OP
       May 16, 2014
    @sandtears
    是的,用IP访问也是跳到 mydomain.com(FF和CHROME才会,IE11不会....)

    @Ellison

    但是我设置了default_server依然无效啊...
    server {
    root /var/www;
    listen 80 default_server;
    server_name mydomain.com;
    ....
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5888 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 06:14 · PVG 14:14 · LAX 23:14 · JFK 02:14
    ♥ Do have faith in what you're doing.