文章来源:阿木工作室
windows下安装Nginx服务器 并配置多站点 - 阿木工作室 - 博客园
1、下载Nginx
链接:http://nginx.org/en/download.html
本次测试时下载的是http://nginx.org/download/nginx-1.20.1.zip
2、修改Hosts文件 C:\Windows\System32\drivers\etc,增加两个虚拟域名
127.0.0.1 nginx.sitea.com
127.0.0.1 nginx.siteb.com
3、修改conf/nginx.conf配置文件,未避免与80端口冲突,测试监听的是8000端口。红色为新增部分。
server {
listen 8000;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 8000;
server_name nginx.sitea.com;
location / {
root F:/nginx_site/site1;
index index.html index.htm;
}
}
server {
listen 8000;
server_name nginx.siteb.com;
location / {
root F:/nginx_site/site2;
index index.html index.htm;
}
}
4、Nginx启动停止等命令
启动:
D:\nginx>start nginx.exe
D:\nginx>nginx.exe
停止:
D:\nginx>nginx.exe -s quit
D:\nginx>nginx.exe -s stop
重新载入
D:\nginx>nginx.exe -s reload
重新打开日志文件
D:\nginx>nginx.exe -s reopen
查看Nginx版本
D:\nginx>nginx -v