说明:
1.为提高网站创建效率和演示效率,文中用于演示的网站均采用当前流行的内容管理系统(CMS)WordPress平台创建
2. 在本地(localhost)配置Nginx支持多域名前,应确保本地已经成功支持了一个本地网站的成功运行。
支持一个本地(localhost)站点的Nginx配置文件内容:
#user nobody;
worker_processes auto;
events {
worker_connections 1024;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile off;
tcp_nopush on;
client_max_body_size 200m;
#默认支持的站点
server {
listen 80 default_server;
server_name localhost;
location / {
root html;
#include wordpress.conf; #这里加载支持wordpress网站修改固定链接的配置
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
正题:
先预设两个模拟站点
1.用来测试用的两个模拟域名(模拟域名可以自行随意命名)
siliconcircuit.asiahttps://siliconcircuit.asia
jianwangzhan.onlinehttps://jianwangzhan.online
对于Windows系统:
- 先进入下面这个地址:C:\Windows\System32\drivers\etc
- 打开hosts文件,在文件最下面添加前面自定义的两个模拟域名
3. 进入Nginx的安装目录,打开conf文件夹下的nginx.conf配置文件
在http的默认server{}后面再添加两个新的server{},两个新server的内容分别是:
#新添加的模拟域名站点1:siliconcircuit.asia
server {
listen 81;
server_name siliconcircuit.asia;
root D:/WNMP/Nginx/html/mulitiWordPress/siliconcircuit.asia/;
index index.php index.html index.htm;
location / {
allow all;
}
}
#新添加的模拟域名站点2:jianwangzhan.online
server {
listen 82;
server_name jianwangzhan.online;
root D:/WNMP/Nginx/html/mulitiWordPress/jianwangzhan.online/;
index index.php index.html index.htm;
location / {
allow all;
}
}
4. 最终的整个nginx.conf配置文件内容如下
#user nobody;
worker_processes auto;
events {
worker_connections 1024;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile off;
tcp_nopush on;
client_max_body_size 200m;
#默认支持的站点
server {
listen 80 default_server;
server_name localhost;
root html;
location / {
#include wordpress.conf; #这里加载支持wordpress网站修改固定链接的配置
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#新添加的模拟域名站点1:siliconcircuit.asia
server {
listen 81;
server_name siliconcircuit.asia;
root D:/WNMP/Nginx/html/mulitiWordPress/siliconcircuit.asia/;
index index.php index.html index.htm;
location / {
allow all;
}
}
#新添加的模拟域名站点2:jianwangzhan.online
server {
listen 82;
server_name jianwangzhan.online;
root D:/WNMP/Nginx/html/mulitiWordPress/jianwangzhan.online/;
index index.php index.html index.htm;
location / {
allow all;
}
}
}
5. 重启Nginx服务,即可同时支持多个网站
访问:siliconcircuit.asia/mulitiWordPress/siliconcircuit.asia/index.php
访问:jianwangzhan.online/mulitiWordPress/jianwangzhan.online/index.php