1

I'm setting up nginx on a Raspberry Pi 4 under Raspbian 11 (Bullseye) but it's refusing connections on http://localhost:80/

This site can't be reached
127.0.0.1 refused to connect

However, it looks like it's running as sudo systemctl status nginx returns...

● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-12-24 15:48:20 PST; 1h 19min ago
       Docs: man:nginx(8)
    Process: 4326 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 4327 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 4328 (nginx)
      Tasks: 5 (limit: 4915)
        CPU: 88ms
     CGroup: /system.slice/nginx.service
             ├─4328 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─4329 nginx: worker process
             ├─4330 nginx: worker process
             ├─4331 nginx: worker process
             └─4332 nginx: worker process

Dec 24 15:48:20 raspberrypi systemd[1]: Starting A high performance web server and a reverse proxy server... Dec 24 15:48:20 raspberrypi systemd[1]: Started A high performance web server and a reverse proxy server.

This is my /etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events { worker_connections 768; # multi_accept on; }

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

}

#mail {

# See sample authentication script at:

# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript

# auth_http localhost/auth.php;

# pop3_capabilities "TOP" "USER";

# imap_capabilities "IMAP4rev1" "UIDPLUS";

server {

listen localhost:110;

protocol pop3;

proxy on;

}

server {

listen localhost:143;

protocol imap;

proxy on;

}

#}

Here's my /etc/nginx/sites-available/default

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

Default server configuration

server { listen 80 default_server; listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

#root /var/www/html;
root /home/scoreboard/wwwroot;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
#   include snippets/fastcgi-php.conf;
#
#   # With php-fpm (or other unix sockets):
#   fastcgi_pass unix:/run/php/php7.4-fpm.sock;
#   # With php-cgi (or other tcp sockets):
#   fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#   deny all;
#}

}

Virtual Host configuration for example.com

You can move that to a different file under sites-available/ and symlink that

to sites-enabled/ to enable it.

#server {

listen 80;

listen [::]:80;

server_name example.com;

root /var/www/example.com;

index index.html;

location / {

try_files $uri $uri/ =404;

}

#}

Here is the directory listing for /home/scoreboard/wwwroot

drwxr-xr-x  2 scoreboard scoreboard 4096 Dec 24 14:54 ./
drwxr-xr-x 19 scoreboard scoreboard 4096 Dec 24 14:36 ../
-rw-r--r--  1 scoreboard scoreboard  180 Dec 24 14:54 index.html

Any help would be appreciated.

Update 1

Using sudo lsof -i :80 -s TCP:LISTEN and sudo lsof -i :443 -s TCP:LISTEN doesn't show any listeners. I suspected this was the case with port 80 and I'm not surprised by the lack of listening on 443, the SSL port.

Update 2

Executing `cat /var/log/nginx/error.log' shows that the error log is empty.

Update 3

I tried adding explicit bindings to the loopback address and Pi's static IP to /etc/nginx/sites-available/default...

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        # New bindings 
        listen 127.0.0.1:80;
        listen 192.168.4.1:80;
    # ...the file continues...

Update 4

Running sudo netstat -anp and it listed all of the ports listening. It's a big list and I culled it down to just the Java app that's running on port 8000 and nginx.

Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp6       0      0 :::8000                 :::*                    LISTEN      672/java

Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node PID/Program name Path unix 3 [ ] STREAM CONNECTED 132043 24462/nginx: master unix 3 [ ] STREAM CONNECTED 132044 24462/nginx: master unix 3 [ ] STREAM CONNECTED 132041 24462/nginx: master unix 3 [ ] STREAM CONNECTED 132046 24462/nginx: master unix 3 [ ] STREAM CONNECTED 132042 24462/nginx: master

But it's still not listening.

amber
  • 153
  • 1
  • 9

0 Answers0