0

I'm trying to redirect my domain url to my local server.

For some reason it work with the localhost (mapping from http://localhost/ to http://127.0.0.1:5000 works), but I can't make it working with my domain name (http://www.example.com)

Here's my nginx conf:

 ... server { listen 80; server_name www.example.com localhost; location / { proxy_pass http://127.0.0.1:5000; proxy_set_header Host $host; } } ... 

Is there's something I am missing?

edit

It seems that the problem was about the reolution of 0.0.0.0, localhost and 127.0.0.1 . Rewriting my proxy_pass to http://0.0.0.0:5000 did the trick. Inversely with my server as long as it match exactly the nginx conf.

My error was because I thought 0.0.0.0 / 127.0.0.1 / was interchangeable. Thanks for your help.

15
  • Do you have a DNS entry for www.example.com that goes to the IP of this server? Commented Mar 14, 2018 at 17:22
  • No I didn't configure my DNS. The only thing I did is use my router conf to point to the correct computer. So when my server point to port 80, I can access to my server through www.example.com. And if I start nginx with the default configuration, I can hit the nginx welcome page through my domain too. What I can't achieve is map www.example.com to my local server from Nginx. Do you think I have to configure my local DNS? Commented Mar 14, 2018 at 17:42
  • Without the DNS entry to point www.example.com to the server you're running the nginx to, your request will never make it to your nginx server to begin with for your nginx to proxy. If you want to test this out, and not update your DNS, just edit your host file so www.example.com points to your server and see what happens. Commented Mar 14, 2018 at 17:45
  • I don't really understand what do you mean exactly by dns resolution. If I launch my server as 'sudo gunicorn -w 2 app:app -b 0.0.0.0:80' it will works from my domaine name. Same if I launch Nginx in standalone (I will get my Nginx welcome page). So the dns works. What is not working is asking Nginx to redirect to my server through my rule, even if it works with 'local'. When you're talking about DNS? Are you talking about my local one on my machine? Commented Mar 14, 2018 at 17:55
  • 1
    I don't believe "proxy_pass to 0.0.0.0:5000 did the trick". Commented Mar 14, 2018 at 20:25

1 Answer 1

2

add a entry to /etc/hosts for your server_name www.example.com

127.0.0.1 www.example.com 

its working for localhost because localhost is mapped by default in /etc/hosts/ file

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.