Skip to content

Instantly share code, notes, and snippets.

@therealechan
Created January 21, 2015 06:42
Show Gist options
  • Select an option

  • Save therealechan/677c440a2a5c242182b7 to your computer and use it in GitHub Desktop.

Select an option

Save therealechan/677c440a2a5c242182b7 to your computer and use it in GitHub Desktop.
Nginx Debuging log

Install and configure Nginx as usual, but can't visit website through IP address.

Debugging

First, I went to Nginx access.log and error.log , I found nothing.

Then I try to use curl to test Nginx wheather can receive the outspace requests

$ curl google.com # It returns nothing!

and I try

$ curl localhost
<!DOCTYPE html>  
<html>  
<head>  
<title>Welcome to nginx!</title>  
<style>  
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>  
</head>  
<body>  
<h1>Welcome to nginx!</h1>  
<p>If you see this page, the nginx web server is successfully installed and  
working. Further configuration is required.</p>

<p>For online documentation and support please refer to  
<a href="http://nginx.org/">nginx.org</a>.<br/>  
Commercial support is available at  
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>  
</body>  
</html>  

I got the whole Nginx default page!

Obviously, the problem is not came from Nginx itself, it's possible the 80 port had been forbidden.

Then I check /etc/sysconfig/iptables

# Generated by iptables-save v1.4.7 on Tue Dec  9 17:55:22 2014
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2885:466223]
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT  
# Completed on Tue Dec  9 17:55:22 2014

These two rules only allow packets pass which are matched.

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

Solution

$ sudo vi /etc/sysconfig/iptables

add config like below to active the 80 port.

-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment