[英]Why nginx redirect all subdomain to non-www, I just setting redirect www to non-www
作業系統:Ubuntu 14.04 LTS
Nginx版本:1.6.0
我想將www重定向到非www,但是以下配置將ALL子域重定向到非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;
}
}
您的重定向在此子句中定義
server {
server_name www.mydomain.com;
listen 80;
return 301 http://mydomain.com$request_uri;
}
刪除行返回301 http://mydomain.com $ request_uri; 並且應該刪除重定向。
如果這是服務器上的唯一站點,則可以刪除整個服務器塊,因為php處理的根目錄和位置是在該服務器上面的server {}塊中定義的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.