nginx下主域名强制跳转到www

1、先监听 exp.com域名,然后转发到www下面

   		server {
   		  listen         80;
   		  server_name    exp.com;
   		
   		  rewrite ^(.*) $scheme://www.$server_name$1 permanent;
   		}
   		
   		#www.exp.com配置
   		server {
   		  listen       80;
   		  root         path;
   		  server_name  www.exp.com;
   		  
   		  location ~ \.php$ {
   		    fastcgi_pass   127.0.0.1:9000;
   		    fastcgi_index  index.php;
   		    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
   		    include        fastcgi_params;
   		   }
   		}

2、在nginx里面配置 rewrite 规则

		server{
		    listen 80;
			server_name www.xxx.com xxx.com;
			if ($host != 'www.xxx.com') {
			rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
		}
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页