Simple Nginx config doesn't work

4

I am a developer with absolutely no server experience, this project I'm working on is my first foray into the world of servers. Basically I have to host an API online, on a Linode server running Nginx on Ubuntu. And I'm having trouble getting a simple server block set up to host a html index page, with just a h1 tag saying 'hello'. I've followed and read various tutorials on getting a simple server block working, I've even got these blocks working on my local machine, but I'm having issues getting it to work on the remote server.

I'll show you some blocks that have failed to work for me on the Linode:

First, a simple block to server a static html page, this works on my local machine:

server {

    listen 8005;
    index index.html;
    root /srv/www/site;

}

another simple block:

server {

    listen [server ip]:8006;
    server_name "";
    index index.html;
    root /srv/www/site;

    location ~/ {

        root /srv/www/site;

    }

}

A block for serving php (works locally):

server {

    listen [server ip]:8007;
    server_name "";
    index index.php index.html index.htm;
    root /srv/www/site;

    location / {

        try_files $uri $uri/ /index.php?q=$uri&$args;

    }

    location ~* \.php$ {

        try_files $uri /index.php;
        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;

    }

}

Whenever I tried to access them through the browser I got server connection timeouts. I do not have any DNS setup with it so I was trying to access it using the server IP and port number:

[server ip]:[port]

or

[server ip]:[port]/index.html

but got nothing.

So one thing that might cause the problem is the fact that another application is being hosted on the server already. It has its own block and is running on its own port. It has its own DNS name pointing to it. But none of this should matter right? As each server block is basically a virtual server or creates a virtual domain. Accessing it through ip and port should work fine, but it aint working!

Thats about all I can think of, my knowledge in this area is maxed out and I need help from smart people!

jonathan

Posted 2015-05-06T11:47:30.153

Reputation:

2What's the output of iptables -nvL ? – Xavier Lucas – 2015-05-06T14:42:47.820

Firewall rules most likely. – None – 2015-05-06T19:40:51.083

so far i've found a few things out, i have allowed the ports through the firewall, and have checked that Nginx is listening on those ports. still nothing though. Also, the live application that is already running on the server is listening on port 80, when changing my simple server block to listen on port 80, it works. so at least my block syntax is correct. What i get when run 'lsof -i :80' i get : http://i.imgur.com/f6WbR7y.png , does *:http mean that all http traffic is directed to port 80?

– None – 2015-05-07T14:04:00.673

@jonathan You should edit your question with the new information. As for the results of the lsof it means that the software listening to port 80 is listening on any interface available on the machine. If you found something like 127.0.0.1:80 this would mean that the software is going to accept only connections that are made on the loopback device on port 80. So a connection coming from an ethernet card would be rejected. – Louis – 2015-05-08T11:14:16.613

Answers

0

try accessing from the same server using 127.0.0.1:8005 - if it works then it's your IP tables. In that case try running something like: iptables -A INPUT -i eth0 -p tcp --dport 8005 -j ACCEPT to open the port.

snoopy

Posted 2015-05-06T11:47:30.153

Reputation: 65