当前位置:

Windows系统在本地(localhost)配置Nginx支持多个网站

访客 2024-01-05 970 0

说明

1.为提高网站创建效率和演示效率,文中用于演示的网站均采用当前流行的内容管理系统(CMS)WordPress平台创建

2.在本地(localhost)配置Nginx支持多域名前,应确护住本金地已经成功支持了一个本地网站的成功运行。

支持一个本地(localhost)站点的Nginx配置文件内容:​​​​​​​

  • #usernobody;
  • worker_processesauto;
  • events{
  • worker_connections1024;
  • multi_accepton;
  • }
  • http{
  • includemime.types;
  • default_typeapplication/octet-stream;
  • sendfileoff;
  • tcp_nopushon;
  • client_max_body_size200m;
  • #默认支持的站点
  • server{
  • listen80default_server;
  • server_namelocalhost;
  • location/{
  • roothtml;
  • #includewordpress.conf;#这里加载支持wordpress网站修改固定链接的配置
  • indexindex.phpindex.htmlindex.htm;
  • }
  • error_page500502503504/50x.html;
  • location=/50x.html{
  • roothtml;
  • }
  • #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
  • location~\.php${
  • roothtml;
  • fastcgi_pass127.0.0.1:9000;
  • fastcgi_indexindex.php;
  • fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
  • includefastcgi_params;
  • }
  • }
  • }
  • 正题:

    先预设两个模拟站点

    1.用来测试用的两个模拟域名(模拟域名可以自行随意命名)

    siliconcircuit.asiahttps://siliconcircuit.asia

    jianwangzhan.onlinehttps://jianwangzhan.online

    对于Windows系统:

    1. 先进入下面这个地址:C:\Windows\System32\drivers\etc
    2. 打开hosts文件,在文件最下面添加前面自定义的两个模拟域名​​​​​​​

    3.进入Nginx的安装目录,打开conf文件夹下的nginx.conf配置文件

    在http的默认server{}后面再添加两个新的server{},两个新server的内容分别是:

  • #新添加的模拟域名站点1:siliconcircuit.asia
  • server{
  • listen81;
  • server_namesiliconcircuit.asia;
  • rootD:/WNMP/Nginx/html/mulitiWordPress/siliconcircuit.asia/;
  • indexindex.phpindex.htmlindex.htm;
  • location/{
  • allowall;
  • }
  • }
  • #新添加的模拟域名站点2:jianwangzhan.online
  • server{
  • listen82;
  • server_namejianwangzhan.online;
  • rootD:/WNMP/Nginx/html/mulitiWordPress/jianwangzhan.online/;
  • indexindex.phpindex.htmlindex.htm;
  • location/{
  • allowall;
  • }
  • }
  • 4.最终的整个nginx.conf配置文件内容如下

  • #usernobody;
  • worker_processesauto;
  • events{
  • worker_connections1024;
  • multi_accepton;
  • }
  • http{
  • includemime.types;
  • default_typeapplication/octet-stream;
  • sendfileoff;
  • tcp_nopushon;
  • client_max_body_size200m;
  • #默认支持的站点
  • server{
  • listen80default_server;
  • server_namelocalhost;
  • roothtml;
  • location/{
  • #includewordpress.conf;#这里加载支持wordpress网站修改固定链接的配置
  • indexindex.phpindex.htmlindex.htm;
  • }
  • error_page500502503504/50x.html;
  • location=/50x.html{
  • roothtml;
  • }
  • #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
  • #
  • location~\.php${
  • roothtml;
  • fastcgi_pass127.0.0.1:9000;
  • fastcgi_indexindex.php;
  • fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
  • includefastcgi_params;
  • }
  • }
  • #新添加的模拟域名站点1:siliconcircuit.asia
  • server{
  • listen81;
  • server_namesiliconcircuit.asia;
  • rootD:/WNMP/Nginx/html/mulitiWordPress/siliconcircuit.asia/;
  • indexindex.phpindex.htmlindex.htm;
  • location/{
  • allowall;
  • }
  • }
  • #新添加的模拟域名站点2:jianwangzhan.online
  • server{
  • listen82;
  • server_namejianwangzhan.online;
  • rootD:/WNMP/Nginx/html/mulitiWordPress/jianwangzhan.online/;
  • indexindex.phpindex.htmlindex.htm;
  • location/{
  • allowall;
  • }
  • }
  • }
  • 5.重启Nginx服务,即可同时支持多个网站

    访问:siliconcircuit.asia/mulitiWordPress/siliconcircuit.asia/index.php

    访问:jianwangzhan.online/mulitiWordPress/jianwangzhan.online/index.php

    发表评论

    • 评论列表
    还没有人评论,快来抢沙发吧~