打开/usr/local/nginx/conf/nginx.conf文档
注释里面的SERVER{}模块
新增加include /usr/local/nginx/vhost/*.conf;
例如
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#新增加的
include /usr/local/nginx/vhost/*.conf;
}
新建/usr/local/nginx/vhost文件夹
vhost文件夹下新建test.conf文档
内容为:
server {
listen 80;
server_name localhost;
location / {
root /usr/local/nginx/html/tp;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#特别要注意修改 ROOT的站点路径和 fastcgi_param 里的document_root
location ~ \.php$ {
root /usr/local/nginx/html/tp;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}