我有一个在Wordpress中运行网站的nginx服务器(1.4.1)。它会自动将www.mysite.com重定向到mysite.com,而没有任何具体的规则。如果最初输入的话,我希望它能够停止并保留www。
请您检查一下我的配置,让我知道可能是什么原因?如果我在图像文件上测试它,重定向不会发生,但在PHP文件上它会...
server {
listen 80;
server_name www.mysite.com mysite.com;
access_log /logs/mysite.com/access.log;
error_log /logs/mysite.com/error.log crit;
root /home/sites/mysite.com/;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors off;
}
}
fastcgi_params:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
答案 0 :(得分:1)
我认为你的问题不是nginx,它是一个wordpress配置,转到wordpress设置并确保你的网站URL没有www。
检查http://yourdomain.com/wp-admin/options-general.php
答案 1 :(得分:0)
这一行是否说它应该同时使用它们作为您网站的正确地址?
server_name www.mysite.com mysite.com;
尝试使用此配置,它将导致任何子域和没有子域的所有流量都转到www.mysite.com对应项。
server {
listen 80;
server_name mysite.com *.mysite.com;
return 301 $scheme://www.mysite.com$request_uri;
}
server {
listen 80;
server_name www.mysite.com;
index index.html;
root /home/mysite.com;
}
哦,不要只是复制/过去,将其调整到您的服务器设置。