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; } }
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?
Making the changes directly to the configuration files on the server means you can test your changes basically straight away. However, If you have a load balancer directing traffic to more than one instance, you have to make the same change in several places.
You need to set your /etc/hosts or C:\Windows\system32\drivers\etc\hosts (as administrator) to reflect the "subdomain". So add 127.0. 0.1 dev. localhost to either file (depending on your platform).
Yes, add '127.0.0.1 sub.localhost' to your hosts file. That sub has to be resolved somehow. That should work.
Then once you're ready to go to the net, yes, add an a or cname record for the subdomain sub.
When I use proxy_pass I also include the proxy.conf from nginx. http://wiki.nginx.org/HttpProxyModule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With