nginx多域名同IP同80端口配置

vi /etc/nginx/nginx.conf

里面有这2句话:

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;


于是我们在这个文件夹下新建多站点配置文件

/etc/nginx/sites-enabled

这里有个默认的default文件,删除

a1.conf

server  
      {
          listen       80;     
          server_name  www.a1.com;     
          index index.html index.htm index.php;#设定访问的默认首页地址   
       root  /var/www/a1;#设定网站的资源存放路径


	location / {

	    index  index.html index.htm index.php; 
	    if (-f $request_filename/index.html){
	    rewrite (.*) $1/index.html break;
	    }
	    if (-f $request_filename/index.php){
	    rewrite (.*) $1/index.php;
	    }
	    if (!-f $request_filename){
	    rewrite (.*) /index.php;
	    }
	}

	location ~ \.php$ {
			fastcgi_pass 127.0.0.1:9000;
			fastcgi_index index.php;
			include fastcgi_params;
	}
     }


a2.conf同上,只是把域名改成a2

service nginx stop

service nginx start

OK启动好了。

(主要是删除default这个文件,好像哪里做限制了,最后记得本地绑定下hosts)












你可能感兴趣的:(nginx)