windows下Nginx配置多域名主机

  • A+
所属分类:网络技术

windows下Nginx配置多域名主机

进入conf文件夹,新建vhost文件夹;

将内部的server配置段提取单独放在一个文件里,存到了conf/vhost下,以方便配置多个虚拟主机。

并在nginx.conf里http配置段内添加了一行 include vhost/*.conf;用来读取vhost下的虚拟主机配置。

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    include vhost/*.conf;  #新增
}

配置主机:

进入vhost文件,新建一个mall.conf(你自己想取的名字)文件。

server {
        listen       80;
        server_name  mall.me; #可添加多个,多个之间“空格”分开

        #autoindex on;#打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件

        location / {
            root   F:/wnmp/wwwroot/mall;
            index  index.html index.htm index.php;

            #此处是伪静态配置
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php/?/$1  last; 
                break;
            } 

        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   F:/wnmp/wwwroot;
        }
        location ~ \.php$ {
            root           F:/wnmp/wwwroot/mall;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

然后重启你的Nginx服务器。

若文章图片、下载链接等信息出错,请在评论区留言反馈,我们将第一时间更新!如有侵权,请联系删除,谢谢!

    发表评论

    :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

    回复后请耐心等待管理员审核,谢谢!