nginx虚拟主机
1 需求
一台服务器的nginx上如果需要运营多个网站,或者把二级域名拆分成不同的web映射目录。就需要使用vhost。web client上请求不同的域名,nginx会根据vhost里的server conf加载不同的配置。
2 配置
conf/nginx.conf
不需要server标签,只要在http标签的最后加上一个include
(conf文件是在conf/vhost/里面,但是这里不是写conf/vhost/*.conf,踩坑了。)
worker_processes 1; error_log logs/error.log error; 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; include vhost/*.conf; }
conf/vhost/jab.com.conf
server { listen 80; server_name www.jab.com jab.com; root /data/jab.com/; #charset koi8-r; access_log logs/jab.com.log main; location / { root /data/jab.com/; index index.php index.html; } 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; } }