楔子
学习了解Nginx配置虚拟主机。2个域名,都配置到
80端口
环境是window
用到的工具
- Nginx (window版本)
- SwitchHosts
hosts管理利器
- cmd工具
ConEmu (x64)
站点
准备2个站点
www.grqpc.cc
和grmpc.cc
SwitchHosts配置window 的hosts
配置
此处只是 server部分的配置,其他配置省略
www.grqpc.com
配置
server {
listen 80;
server_name www.grqpc.cc;# 虚拟主机
# 开启文件目录后,编码需要按照操作系统来设置,否则中文名显示乱码(window上一般是gbk,Linux一般是utf-8或者不设置)
charset gbk;
#开启文件目录 nginx.conf
autoindex on;
autoindex_exact_size off;#off 以KB,MB,GB显示文件大小;on 以 bytes显示文件大小;
autoindex_localtime on; #on
access_log logs/host.access.log;
#位置B
location ~ images{
#location /images{
#开启文件目录(如果配置在外面,下面的“位置A” 也会按照文件目录显示)
#autoindex on;
root D:/pic;
index 110.png 0.jpg;
}
# 位置A
location / {
root html;
index index.htm index.html ;
}
}
grmpc.cc
配置
server {
listen 80;
server_name grmpc.cc;
location / {
root D:/pic;
index index.html 110.png 0.jpg;
}
}
# 修改配置文件后重新加载。
nginx.exe -t # 执行此命令,注意文件位置