cannot access nginx from outside

Cannot Access NGINX From Outside

NGINX is a powerful web server used by many websites and organizations. However, sometimes it might happen that you have configured NGINX server but are unable to access your website from external public IP or outside box. This is a common issue faced by new system administrators. In this article, we will learn how to fix this problem where you cannot access NGINX from outside.


Cannot Access NGINX From Outside

Here are the steps to take if you cannot access NGINX from outside.


1. Update server_name

server_name directive is the name(s) of domains and subdomains that your NGINX server answers to. If you enter an IP address for its value then you will not be able to access NGINX. Here is an example of incorrect configuration.

server_name 54.54.32.21;

Here is the example of correct configuration. In this case, your NGINX server will serve requests sent to www.example.com.

server_name www.example.com;

Basically you need to use one or more domain/subdomain names, instead of IP address. For example, if you want the same server to server requests for www.example.com and blog.example.com, you can update the server_name directive as shown below.

server_name www.example.com blog.example.com

If you want to serve all domains and subdomains, update server_name as shown.

server_name _;

But please be careful before you do the above change, since you don’t want your server to serve all domains & subdomains unnecessarily.



2. Update /etc/hosts

If the above step does not work for you, then open /etc/hosts file in text editor.

$ sudo vi /etc/hosts

Add the public IP address of your NGINX server along with your domain name.

54.54.32.21 www.example.com

Save and close the file.


3. Update firewall

If the above steps don’t work for you, then probably your firewall is blocking external inbound traffic. In such cases, just run the following command to disable firewall.

$ sudo ufw disable

After the firewall is disabled, check if your website is accessible. If so, then you need to re-enable our firewall but open port 80, or another port, on which your NGINX server is running.

If you are not even able to access NGINX from your local machine, then most likely another process is running on the port required by NGINX. In such cases, update the port number mentioned in ‘listen’ directive to run the NGINX on a different port. If you find that it is working, then use netstat command to find out which process if running on port 80 required by NGINX.

$ sudo netstat -tulpn

In this article, we have learnt how to fix the issue that you cannot access NGINX from outside.

Also read:

How to Undo Git Rebase
How to Stop Tracking Folder in Git Without Deleting it
Bash Loop Through Files in Directories & Subdirectories
How to Remove Git Ignore Files from Git Repository
How to Stop Python Code After Certain Amount of Time

Leave a Reply

Your email address will not be published. Required fields are marked *