【Nginx】虚拟主机配置

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的主页

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值