前期准备工作:
0 1 2 3 4 5 6 7 |
[root@lnmp ~]# mkdir /usr/local/nginx/conf/extra -p #其中/usr/local/nginx/conf是nginx的默认配置文件 [root@lnmp ~]# mdkir /var/site/www -p #建立网站目录 [root@lnmp ~]# mdkir /var/site/bbs #bbs目录 [root@lnmp ~]# cd /usr/local/nginx/conf/ [root@lnmp conf]# egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf >extra/nginx-www.conf #空行、注释排除,且放置在/var/local/nginx/conf/extra目录下的nginx-www.conf [root@lnmp conf]# egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf >nginx-default.conf [root@lnmp conf]# mv nginx.conf nginx.conf.backup [root@lnmp conf]# mv nginx-default.conf nginx.conf |
nginx主nginx.conf:
0 1 2 3 4 5 6 7 8 9 10 11 |
[root@lnmp conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; include extra/*.conf; #加载虚拟主机配置文件 default_type application/octet-stream; sendfile on; keepalive_timeout 65; } |
虚拟主机配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@lnmp conf]# cat extra/nginx-www.conf server { listen 80; server_name note.t4x.org; location / { root /var/site/www; index index.html index.htm index.php; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/site/www; } error_page 404 /404.html; location = /404.html { root /var/site/www; } location ~ \.php { root /var/site/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/site/www$fastcgi_script_name; include fastcgi.conf; } } |
申明:本文由BYRD原创(基于NGINX),未经许可禁止转载! SourceByrd's Weblog-https://note.t4x.org/basic/nginx-vhost-config/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!