14

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?

Eamorr
  • 616
  • 5
  • 14
  • 27

3 Answers3

19

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
kaji
  • 2,528
  • 16
  • 17
  • 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 07 '16 at 22:16
  • 1
    According to the [nginx doc](http://nginx.org/en/docs/http/server_names.html), **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
2

I had the same problem a few months ago when I was trying to run ngnix on my Ubuntu system and access the services from another Windows system. I was not able to access any port service like http://127.0.0.1/8000 but after some time, I fixed this by turning off the firewall on 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
Laurel
  • 129
  • 7
  • The firewall was the problem for me too. In my case (on Fedora 32) I used systemctl stop firewalld to check it. – Benjamin Jul 02 '20 at 11:14
0

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

A09hopper
  • 11
  • 2