8

I have nginx running on port 81. I can telnet using telnet 127.0.0.1 81 and everything is fine.

But when I try to telnet to my machine from my Mac (an external IP address), I just get this error:

telnet: connect to address 109.123.x.x: Connection refused
telnet: Unable to connect to remote host

Here is my /etc/nginx/sites-available/default file:

server {
        listen   81; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /usr/share/nginx/www;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name 109.123.x.x;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
        }
        ...

I've opened Ubuntu Firewall (ufw) to allow port 81.

I'm totally stuck now.

Anyone have any ideas?

17

You have server name as

server_name 109.123.x.x;

This is wrong !!!!!

Put any name not number like

server_name mywebsite.home;

and put mywebsite.home as the IP of the nginx server in your host file(/etc/hosts) i.e in your mac like in format

109.123.X.X mywebsite.home

where X.X gets replaced with numbers

or

If you want to serve all the request , simply put

server_name _;

If that does not solve the things , check below

It's either your firewall i.e iptables blocking your traffic or you have your nginx listening only at localhost i.e 127.0.0.1

Disable firewall

sudo ufw disable

Check the listening address for port 81

sudo netstat -tulpn
  • I switched to port 8080 and it's working now. Might be something to do with a priviliged port or maybe my 3G connection blocks port 81. Anyway, it's working now. Many thanks for your help. – Eamorr Feb 18 '12 at 18:37
  • If its an instance in the cloud like rackspace or AWS, check your Security Groups. By default port 22 and 80 are the only ones usually open. – radtek Oct 28 '14 at 11:57
  • the sudo ufw disable did it for me. – GG_Python Sep 7 '16 at 22:16
  • According to the nginx doc, using ip address has server_name is not wrong. "If someone makes a request using an IP address instead of a server name, the “Host” request header field will contain the IP address and the request can be handled using the IP address as the server name": – Gabriel Glenn Mar 28 '19 at 10:03
1

I have the same problem a few month ago when i am trying to run ngnix on my ubuntu system and accessing the services from another windows system. but can not able to run access any port service like http://127.0.0.1/8000 after sometime i overcome to this by turnoff the firewall of my ubuntu system.

command to turn off the firewall:

    sudo ufw disable

you can also check the status of your firewall first:

    sudo ufw status
0

Tips which helped me: A.)Port forward B.)Set the public IP as server_name These steps worked for me especially tip A.)

  • Server name should never really be an IP. – Matt Jul 24 '16 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.