0
操作系統:Ubuntu的LTS 14.04爲什麼nginx的重定向所有子域名不帶www的,我只是設置重定向到WWW非www
Nginx的版本:1.6.0
我想重定向到WWW非www,但以下配置將所有子域重定向到非www。
例如,我訪問test.mydomain.com/index.php也重定向到mydomain.com/index.php
訪問IP_ADDRESS/index.php的同時重定向到mydomain.com/index.php,測試在FF 26和Chrome 34上,但IE11不重定向。
http {
gzip on;
include mime.types;
sendfile on;
default_type application/octet-stream;
keepalive_timeout 65;
server {
listen 80 default_server;
server_name mydomain.com;
root /var/www;
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
location/{
index index.html index.htm index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
server {
server_name www.mydomain.com;
listen 80;
return 301 http://mydomain.com$request_uri;
}
}
對不起我的英文。我只想將www重定向到非www。其他子域不重定向。 – consatan
嘗試將'return 301 ...'放入'if($ http_host〜*^www \ .mydomain \ .com $){'[here]'}'。我在配置中看不到任何錯誤。 – Deadooshka
@Deadooshka我很抱歉!我測試了我的windows 8.1筆記本電腦,在%windir%\ system32 \ drivers \ etc \ hosts文件中設置了本地dns,但失敗了。我嘗試在Ubuntu虛擬機上使用/ etc/hosts本地dns使用curl,這是工作。我在我的Asus RT-N16路由器(使用AsusWRT Merlin固件)上設置本地DNS,現在都可以使用。我想添加評論,但我不能昨天登錄,thx中國GWF! – consatan