centos下Nginx虚拟主机配置步骤

作者:袖梨 2022-06-30

前期准备工作:

[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:

[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;
}

虚拟主机配置:

[root@lnmp conf]# cat extra/nginx-www.conf
    server {
        listen       80;
        server_name  www.111com.net;
        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;
        }
    }

相关文章

精彩推荐