2

I want to use NGINX as a proxy server for my application. My application (say 'abc') is running on port 8000 on my machine. And NGINX is running on the same machine. A part of the configuration looks like:

server {
    listen 80;
    server_name my.example.net;
    location / {
         proxy_pass http://localhost:8000/abc;
    }
}

The configuration file when used allows me to test my app by using localhost in the address bar. However, http://my.example.net does not work. My app does not load. I get an error that the page could not be found.

Any idea what could be wrong?

7
  • Why place my.example.net twice on the server_name line? And does that hostname resolve to the system where nginx is running on?
    – wurtel
    Feb 27, 2015 at 10:50
  • Yes. The app with the actual URL is on the same machine as NGINX. I was looking for examples online to see what I was doing wrong. In some places I found the hostname repeated in the server_name directive. Using it once doesn't make a difference. localhost still works and my.example.net still doesn't.
    – Prachi
    Feb 27, 2015 at 14:57
  • I mean whether from the command line on yur client system (where you run the browser) telnet my.example.net 80 will actually reach that system. As for the server_name thing: I think you overlooked that often with and without a leading www. is shown. Does does not work mean you get no connection, or the wrong content, or whatever? Please elaborate in your question.
    – wurtel
    Feb 27, 2015 at 15:07
  • I am really sorry for not being clearer. Unfortunately unix.stackexchange.com doesn't let anyone with a low reputation post more than one URL in one post. So I have not been clearer.
    – Prachi
    Feb 27, 2015 at 17:23
  • When I say that localhost in the address bar works, I mean that if I use localhost (i.e. 'http' + '://' + 'localhost') in the address bar of my browser, my application gets loaded.
    – Prachi
    Feb 27, 2015 at 17:35

1 Answer 1

1

I found out the solution. The solution was to use virtual hosts in NGINX. I set server_name as my.example.net in nginx.conf. And then updated my /etc/localhosts file as follows:

127.0.0.1 localhost my.example.net

And that fixed the problem.

2
  • 1
    usually there is no /etc/localhosts file on linux machine
    – stiv
    Jan 3, 2020 at 8:24
  • You probably mean /etc/hosts. Apr 2, 2020 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .