Welcome! Log In Create A New Profile

Advanced

simple Nginx config not working

Posted by jonathan888 
simple Nginx config not working
May 06, 2015 08:54AM
hello,

i am a developer with absolutely no server experience, this project im 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 im 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 im having issues getting it to work on the remote server.

il 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!

any help is greatly appreciated, thanks!
Re: simple Nginx config not working
May 06, 2015 08:59AM
selinux? firewall/iptables blocking ports? are your server blocks listen values actually listening on their ports? (netstat -an)

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: simple Nginx config not working
May 06, 2015 09:54AM
thanks, netstat tells me that nginx is listening on the ports i want,

and i used this command to try open the port i want

iptables -A INPUT -p tcp --dport 8007 -j ACCEPT

and it ran fine, then listing the iptable rules i see there is a new rule:

ACCEPT tcp -- anywhere anywhere tcp dpt:8007

that means ive opened up that port yes?
Re: simple Nginx config not working
May 06, 2015 02:01PM
It looks like it yes, so what happens now with accessing on port 8007 ?
Also check nginx logfiles to see if it receives any requests.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: simple Nginx config not working
May 07, 2015 06:02AM
thanks,

checking var/log/error.log, i see whats in the attached image.

i get nothing in the access logs, i've also tried setting up the error/access logs using the directives in the server blocks, pointing to log files inside the application root folder. The logs files are created, but i get no entries into them.

it seems to be the same thing thats happening, connection timeouts. could it be something like not having read permissions in that directory? so when the files are trying to be served, the server isn't allowed to read from the directory? i cant imagine this being the problem as everything is done from the root user.
Attachments:
open | download - errors.jpg (104.8 KB)
Re: simple Nginx config not working
May 07, 2015 06:16AM
Can you post the error.log or paste the image elsewhere, the forums attachments don't work very well.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: simple Nginx config not working
May 07, 2015 07:17AM
sure

http://i.imgur.com/BORWW0F.jpg


it seems like a strange error, saying address is already in use. The server block tells nginx to listen to that port,
sudo netstat -tapen | grep ":8005/6/7 " tells me that nginx is listening on that port. I've opened the port to the internet with the firewall.

'Address already in use', its hardly something to do with some sort of setting somewhere thats telling nginx to only allow traffic coming into this IP to go to one port and one domain?

here is the config for the application already running:

server {

listen 8001;
server_name www.runningapp.com runningapp.com;

index index.php index.html index.htm;
root /usr/share/nginx/www/app/webapp;
access_log /usr/share/nginx/www/app/logs/access.log;
error_log /usr/share/nginx/www/app/logs/error.log;
port_in_redirect off;

gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_buffers 16 8k;
gzip_http_version 1.0;

gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;

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

location ~* /\.ht {
deny all;
access_log off;
log_not_found off;
}

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;

}

}


doesnt look like there is anything there about restricting the IP, although it probably wouldn't exist here. Is this even possible to do!



Edited 1 time(s). Last edit at 05/07/2015 07:18AM by jonathan888.
Re: simple Nginx config not working
May 07, 2015 07:50AM
If the port is in use then its in use... nothing much nginx can do about that.
You need to find out who's using that port or why it's blocked from being used.
netstat -aln | grep portnumber

It might also be possible that you can't run 2 instances of nginx on the same machine. Kill all nginx instances and run your config to see if this might be the case.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: simple Nginx config not working
May 07, 2015 09:41AM
the results of - netstat -tapen | grep ":800x"

http://i.imgur.com/yCWyiEa.png


results of - lsof -i :80 (port 80 being the port the live application is listening on)

http://i.imgur.com/f6WbR7y.png


does '*:http' mean that port 80 is assigned to listen to all http trafic?

i had an interesting discovery, just to test it out, i set my most simple block (the port 8005 one from above) to listen on port 80. And lo and behold, my page appeared! when going to [ip]:80 or even just [ip].

also i should mention that the above block for the running application is wrong, its actually listening on port 80 also, but when hitting [ip]:80 or [ip] i only get directed to the simple block i created. but hitting the proper DNS address takes me to the application.

so what i gather is that many domains can be served through the one port? I



Edited 2 time(s). Last edit at 05/07/2015 09:49AM by jonathan888.
Re: simple Nginx config not working
May 07, 2015 09:55AM
please disregard the stuff i mentioned about the two domains being accessed from the one port, i was wrong, turns out setting my simple block to listen on :80 just overrides the other one!
Re: simple Nginx config not working
May 07, 2015 01:16PM
jonathan888 Wrote:
-------------------------------------------------------
> so what i gather is that many domains can be served through the one
> port? I

Yes, http = port 80, you still need to figure out which config of nginx is running on those ports, see also my previous post.

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 133
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready