如何在本地主机上测试Nginx子域 [英] How to test nginx subdomains on localhost

查看:105
本文介绍了如何在本地主机上测试Nginx子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在将配置上传到服务器之前测试nginx子域.我可以在本地主机上对其进行测试吗?我尝试

I want to test nginx subdomains before uploading config to the server. Can i test it on localhost? I try

server {
    listen       80;
    server_name  localhost;

    location / {
        proxy_pass http://localhost:8080;
    }
}

server {
    listen       80;
    server_name  sub.localhost;

    location / {
        proxy_pass http://localhost:8080/sub;
    }
}

它不起作用.我应该更改我的主机文件以使其正常工作吗?另外,将网站上传到服务器后,我应该更改DNS记录并添加sub.mydomain.com吗?

And it does not work. Shoulld i change my hosts file in order to make it work? Also, after uploading site to the server should i change DNS records and add sub.mydomain.com?

推荐答案

是的,将'127.0.0.1 sub.localhost'添加到您的主机文件中.该子必须以某种方式解决.那应该起作用.

Yes, add '127.0.0.1 sub.localhost' to your hosts file. That sub has to be resolved somehow. That should work.

然后,一旦您准备好上网,是的,为子域子项添加a或cname记录.

Then once you're ready to go to the net, yes, add an a or cname record for the subdomain sub.

当我使用proxy_pass时,我还包括了nginx的proxy.conf. http://wiki.nginx.org/HttpProxyModule

When I use proxy_pass I also include the proxy.conf from nginx. http://wiki.nginx.org/HttpProxyModule

这篇关于如何在本地主机上测试Nginx子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆