找到安装的nginx.conf配置文件
http
{
server{}
}
server即为要配置的站点
新建一个test.conf文件 编辑内容为,注意 #注释标记可能不被识别,所以删除了所有注释内容
server {
listen 8080;
server_name test.com;
location / {
root /var/svn/;
index default.php index.php index.html index.htm;
rewrite ^/(\w+)\.html$ /$1.php;
rewrite ^/(\w+)/(\w+)$ /$1/$2.php;
}
error_page 404 /error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root /var/svn/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/svn/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
然后在nginx.conf的http{}下添加include引用
http{
include /usr/local/nginx/conf/VirtualHost/test.conf;
}
重新启动nginx 根据端口号就能访问不同站点了