can't get nginx to work
I am using nginx for the first time and I cannot find why I cannot get it going under Debian 9.
I am trying to test plain html files located on a Linode before assigning DNS records which seems to be the conventional way of testing without giving world access to the files. When I ssh to the Linode IP address, I can see all the files and read them with nano. I have tried to have the "server blocks" in /etc/nginx/conf.d and then move them to /etc/nginx/sites-available with symlinks in sites-enabled, in both cases, the config files are found to be correct. I tried /etc/hosts: ip_address hostname.mydomain.tld and ip_address mydomain.tld ip_address www.mydomain.tld The results are invariably a long "waiting for ip_address" followed by "connection reset...." although at one stage I got a 404 on index.html but I could not isolate the difference in the code. It seems the problem is with the hosts file or hostname or both which seem to me to have correct values. I simply cannot find a tutorial or howto on this specific subject. Has anyone any suggestion? Thank you for your help |
First you should simply try from the same computer:
Code:
wget -S http://127.0.0.1/ |
Quote:
Regards |
Quote:
Quote:
It seems nginx fails before being able to report anything wrong and it's not my connection since I can access LQ. |
Quote:
Do you have any reason to think that it mysteriously fails before writing an error log, or is that a product of imagination? ;) You most likely do not have nginx configured to listen on your Linode's IP address, or your firewall is not configured to allow traffic on port 80. Can you post the appropriate parts of your nginx configuration (obscure the IP address if desired). Also please post the output of iptables -L INPUT, or other relevant firewall rules. In case you have not seen it here is a Linode page with relevant nginx configuration info. Make sure your server port/IP and names are properly defined, and that your server name is in your hosts file, restart nginx. |
Quote:
Code:
Connecting to 127.0.0.1:80... failed: Connection refused. Here is the main config from /etc/nginx/nginx.conf Code:
user nginx; Code:
server { |
Code:
Connecting to 127.0.0.1:80... failed: Connection refused. Code:
fuser -n tcp 80 |
Code:
systemctl status nginx Code:
● nginx.service - nginx - high performance web server Code:
fuser -n tcp 80 |
It might very well be not listening on port 80. Try lsof again:
Code:
lsof -nP -p 31195 -a -i |
Code:
lsof -nP -p 31195 -a -i |
Code:
iptables -L |
It seems not running at all. You should ask a unix-administrator for help.
|
In addition to possibly not running nginx process, I see no actual handling for HTTP in the firewall rules (although UFW rules can be difficult to follow). It looks to me as if HTTP/HTTPS requests would end up at the end of the INPUT chain and would default to the DROP policy handler - so even if nginx were running you cannot reach it from outside.
I agree that what you need is unix server admin help as this is not a programming problem. If you would like to request that your question be moved to Linux Server or other forum please use the Report button to request that. |
Thank you for the suggestions which I have followed. I am a bit more familiar with Apache2 and find Nginx far more complicated, perhaps erroneously, would I have a better chance of success moving to Apache2 or am I likely to face similar problems?
|
Quote:
The problems you seem to be having are not really nginx specific, so you would likely have them with Apache as well. For example, the firewall rules are independent of the web server being used and will need to allow HTTP/S requests to pass no matter what web server is in use. And any webserver must be configured to listen on the external interface and proper port numbers or incoming traffic cannot reach it. The configuration syntax and file locations may differ, but the "thing" being configured is ultimately the same for all. You also need to approach such problems in a more structured way, somewhat like the path this thread has taken. That is, you first should determine unambiguously whether or not the web server is actually running, ps being an obvious choice, and verify startup and error messages in the log. Once you know it is running, check what it is listening to for incoming requests, lsof or netstat are helpful here. Once you know it is running and listening, verify firewall rules are in place to allow incoming requests through, and if not add those rules. At this point you should receive a response from the server, either a page or an error message. The point of seeking unix admin help is that all these are basic skills and structured troubleshooting methods which any unix admin would do more or less automatically and quickly. Building those skills and thought processes are very important to anyone running a web facing server. Good luck! |
nginx is not listening to port 80
Code:
wget -S http://127.0.0.1/ There seems to be only one process running on port 80, could it block access to other processes? If so how can I safely fix the problem? Code:
netstat -lnp | grep -E '80' |
^^ That grep is not matching on port 80. There is nothing listening on port 80
It's matching on 8688001 Here's what that command shows on a server that does have something listening on port 80: Code:
# netstat -lnp | grep -E '80' So your web server is not running (as has been said) |
Moderator Response
Moved: This thread is more suitable in <Linux - Server> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Don't just easily give up. I have been using nginx, even on my development platform. At a minimum, let us start with this test configuration:
$ cd /etc/nginx/sites-available $ sudo mv localhost localhost.orig (just ignore if no file present yet) $ sudo vi localhost Code:
server { $ sudo ln -sf ../sites-available/localhost . Check your configuration files for possible error: $ sudo /usr/sbin/nginx -t -c /etc/nginx/nginx.conf Go on if no error $ sudo /etc/init.d/nginx start Quick check if running... $ pidof nginx PID numbers should be listed right below the command. For errors, check /var/log/nginx/localhost_error.log Code:
wget localhost |
Sorry, I forgot 'sudo'.... I already edited my previous post to include 'sudo'...
|
The instructions from Linode recommended to insert the following two lines in the server block:
Code:
listen 80; Code:
listen [::]:80 ipv6only=on default_server; Code:
listen [::]:80 default_server; Thank you all for your patience. |
listen 80; # ipv4
listen [::]:80; # ipv6 |
All times are GMT -5. The time now is 05:43 PM. |