nginx虚拟机的配置
基于端口号的虚拟主机配置:
根据不同的端口号进行配置:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 8081;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
基于域名的虚拟机配置:
server {
listen 80;
server_name www.nqq.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.test.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
还得需要修改本地电脑的host文件:
一个域名,对应一个IP地址
通过DNS域名解析服务器,可以将域名解析为IP地址
这里 通过修改host文件,指定域名的IP地址
host劫持
是指在host文件中,配置域名和IP地址,当访问域名的时候
因为,host文件中已经有了域名所对应的IP地址
所以,不再需要访问DNS服务器进行解析,直接访问对应的IP地址
host文件的位置
C:\Windows\System32\drivers\etc
基于ip的虚拟机配置:
server {
listen 80;
server_name 192.168.19.128;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
修改了配置文件,都需要/usr/local/nginx/sbin/nginx -s relaod(软重启)
然后访问即可:localhost:8081 ,www.nqq.com , 192.168.19.128 都可以访问nginx的主页