nginx使用vhost子目录

本文详细介绍了如何在Nginx中配置多个虚拟主机,通过在主配置文件中包含额外的子配置文件实现灵活的网站托管。示例展示了如何设置监听端口、域名、字符集、根目录以及PHP处理配置。
在主配置文件http模块最后添加如下一句话


[root@host-10-1-1-161 ~]# vi /etc/nginx/nginx.conf
include /etc/nginx/conf.d/*.conf;

[root@host-10-1-1-161 ~]# mkdir -p /etc/nginx/conf.d

把主配置文件的server复制到conf.d下面就可以
 

主配置文件实例:

[root@bogon conf.d]# cat /etc/nginx/nginx.conf
user root root;
worker_processes  1;
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"';

server {
        listen 80;
        server_name www.test.com;
    charset    utf-8;
    location / {
    root /var/www/www.test.com;
        index index.php index.html index.htm;
        }
     
        location ~ \.php$ {
        root html;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /var/www/www.test.com$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    include /etc/nginx/conf.d/*.conf;    
}
 

子配置文件实例

[root@bogon ~]# cat /etc/nginx/conf.d/test1.conf 
server {
        listen 8083;
        server_name www.test1.com;
    charset    utf-8;
    location / {
    root /website;
        index index.php index.html index.htm;
        }
     
        location ~ \.php$ {
        root html;
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /website$fastcgi_script_name;
            include fastcgi_params;
        }

}

 

转载于:https://www.cnblogs.com/effortsing/p/10012441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值