OS:Ubuntu 14.04 LTS
Nginx version: 1.6.0
I want redirect www to non-www, but the following config redirect ALL subdomain to non-www.
for example, I visit test.mydomain.com/index.php also redirect to mydomain.com/index.php
visit ip_address/index.php also redirect to mydomain.com/index.php, test on FF 26 and Chrome 34 but IE11 not redirect.
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;
}
}
Your redirect is defined in this clause
server {
server_name www.mydomain.com;
listen 80;
return 301 http://mydomain.com$request_uri;
}
remove the line return 301 http://mydomain.com $request_uri; and that should remove the redirect.
if this is the only site on the server you can remove that whole server block because the root and location for php processing is defined in the server{} block above this one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.