Nginx配置多个虚拟主机利用include减少代码量的方式

虚拟主机的配置,一个server就代表一个虚拟主机,这里可重复设置的配置很多,建议使用include,设置多个主机的时候可以减少配置文件的代码量;
修改配置文件vim /usr/local/nginx/conf/nginx.conf
找到http{

server {
listen 80 default_server;
上边 插入以下代码

include /usr/local/nginx/conf.d/*.conf;

进入 cd /usr/local/nginx/conf.d/ 目录
创建文件 vim localhost.conf

内容如下:

server {
        listen       3700;
        server_name  localhost;
        error_log /var/log/nginx/localhost-error.log;#错误日志所在目录
        rewrite_log on; # 开启重写规则日志
        #access_log  logs/host.access.log  main;
        root   /data/web/localhost-api/web;//网站文件所在目录
        location /static/ {
            root /data/web/localhost-api/;
        }   
#       location ~\.jpg|\.png|\.jpeg|\.gif|\.js|\.html|\.css$ {
#           root /data/web/localhost-api/static;
#       }
        location /uploaded/ {
            root /data/web/localhost-api/;
        }   

        location / { 
            index  index.php index.html index.htm;
            if (!-e $request_filename){
                rewrite ^/(.*) /index.php?r=$1 last;
                #rewrite /index.html /index last;
            }
        }
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           /data/web/localhost-api/web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  LOCAL_ENV          "localhost";//定义环境变量
            include        fastcgi_params;
        }

    }


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值