Windows下Nginx多域名配置实战指南
本示例分享Nginx多域名配置的简易方法,供读者参考详细操作。
首先了解Windows系统中Nginx安装后的目录结构。

接着查看nginx-1.12.1文件夹内conf/nginx.conf文件的原始内容。
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80 default_server;
server_name localhost default_server;
root html;
location / {
index index.html index.htm;
}
}
include ../vhost/*.conf;
}
随后检查vhost目录中a_com.conf配置文件的具体代码。
server {
listen 80;
server_name www.a.com;
root D:/test/;
location / {
index index.html index.htm;
}
}
然后查看vhost目录中b_com.conf配置文件的具体代码。
server {
listen 80;
server_name www.b.com;
root D:/test2/;
location / {
index index.html index.htm;
}
}
在本地D盘新建test与test2两个文件夹,并分别在其中创建index.html文件。
编辑C盘路径C:\Windows\System32\drivers\etc下的hosts文件,添加相应记录。
127.0.0.1 www.a.com
127.0.0.1 www.b.com
使用cmd命令行工具进入Nginx安装根目录执行相关指令。
输入nginx.exe启动服务。
运行nginx -t命令检测配置文件语法是否正确。
执行nginx -s reload命令重新加载配置。
使用nginx -s stop命令停止服务。
打开浏览器输入对应网址进行验证。
项目源码托管于github仓库:https://github.com/chengzao
以上就是全部内容,希望能帮助到大家,欢迎继续支持本站。