NGINX fails to start

Hi, everybody!

I’m trying to install discourse on a subdomain.

My main domain is running wordpress, which was built using docker-compose.

The subdomain and the domain are using the same VPS server.

For the installation I followed this guide: https://meta.discourse.org/t/run-other-websites-on-the-same-machine-as-discourse/17247

Unfortunately, NGIX cannot be started. When I run the systemctl status nginx command, the following message appears:

× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2024-03-08 07:06:36 CST; 1h 14min ago
       Docs: man:nginx(8)
    Process: 27329 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 27330 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 42ms

Mar 08 07:06:33 vmi1695712.contaboserver.net systemd[1]: Starting A high performance web server and a reverse proxy server...
Mar 08 07:06:33 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:34 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:34 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:35 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:35 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Mar 08 07:06:36 vmi1695712.contaboserver.net nginx[27330]: nginx: [emerg] still could not bind()
Mar 08 07:06:36 vmi1695712.contaboserver.net systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Mar 08 07:06:36 vmi1695712.contaboserver.net systemd[1]: nginx.service: Failed with result 'exit-code'.
Mar 08 07:06:36 vmi1695712.contaboserver.net systemd[1]: Failed to start A high performance web server and a reverse proxy server.

My site file for Discourse:

# 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;

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

        server_name forum.ictsharks.com;

        location / {
                proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;
                proxy_set_header Host $http_host;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Real-IP $remote_addr;
                # 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;
        #}
}

I’ve checked it several times, but I can’t figure out where the error is.

Sorry, I’m a beginner with Linux / NGINX / Docker things. Any advice would be appreciated. Thank you.

1 Like

Is there a different webserver on that machine that is hogging port 80?

1 Like

Did you change the ports in the app.yml so that Discourse isn’t trying to use the ports that NGINX wants?

This is an advanced setup that requires understanding of DNS, https and certificates, nginx, reverse proxies, docker, and routing.

1 Like

As I mentioned, wordpress is running on the main domain.

If I understood correctly, the other NGIX works in the container together with wordpress.

I followed this tutorial: How To Install WordPress With Docker Compose | DigitalOcean

If I run the netstat -tulnp command, this is what I get:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      419/systemd-resolve
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1192/docker-proxy
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      463/sshd: /usr/sbin
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1179/docker-proxy
tcp6       0      0 :::22                   :::*                    LISTEN      463/sshd: /usr/sbin
udp        0      0 127.0.0.53:53           0.0.0.0:*                           419/systemd-resolve

The instructions suggest commenting them, so I did:

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  # - "80:80"   # http
  # - "443:443" # https

I understand DNS records, https and certificates. Only the rest is new to me.

Don’t worry, I know how to google and I’m a fast learner :wink:

1 Like

Before you started this, was it behind a working NGINX reverse proxy that you’re adding Discourse to?

Or if Apache/WordPress was running before, that’s what’s got port 80?

Oh, it looks like docker-proxy has port 80, so maybe you had your WordPress behind docker-proxy?

Maybe docker ps to see if you can see what docker

1 Like

As I stated, I believe the other NGIX (the one for wordpress) works in a container together with MySQL, and Wordpress.

This is what I get by running docker ps command:

CONTAINER ID   IMAGE                        COMMAND                  CREATED          STATUS          PORTS                                      NAMES
6ca4cbec2c88   local_discourse/app          "/sbin/boot"             51 minutes ago   Up 15 minutes                                              app
4a3ebdd9f5b5   nginx:1.15.12-alpine         "nginx -g 'daemon of…"   20 hours ago     Up 15 minutes   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   webserver
42c4211a2fb6   wordpress:5.1.1-fpm-alpine   "docker-entrypoint.s…"   2 days ago       Up 15 minutes   9000/tcp                                   wordpress
5b588a7435ad   mysql:8.0                    "docker-entrypoint.s…"   2 days ago       Up 15 minutes   3306/tcp, 33060/tcp                        db

That would be why the external nginx cannot boot, as the ports are taken by the internal one. You probably need to shut that container down and transfer it’s config for Wordpress to the outer nginx layer.

Also, those are separate containers, the nginx is separate from MySQL and WordPress.

1 Like

I shut down the webserver (NGIX container) and tried to start the external NGIX. Still not working.

You’re right. It’s my fault. I thought all the apps mentioned were in one container.

One container = one application/program :wink:

What’s docker ps and netstat -tulnp look like now?

CONTAINER ID   IMAGE                        COMMAND                  CREATED       STATUS       PORTS                 NAMES
6ca4cbec2c88   local_discourse/app          "/sbin/boot"             3 hours ago   Up 2 hours                         app
42c4211a2fb6   wordpress:5.1.1-fpm-alpine   "docker-entrypoint.s…"   2 days ago    Up 2 hours   9000/tcp              wordpress
5b588a7435ad   mysql:8.0                    "docker-entrypoint.s…"   2 days ago    Up 2 hours   3306/tcp, 33060/tcp   db

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      418/systemd-resolve
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      462/sshd: /usr/sbin
tcp6       0      0 :::22                   :::*                    LISTEN      462/sshd: /usr/sbin
udp        0      0 127.0.0.53:53           0.0.0.0:*                           418/systemd-resolve

Not much else I can do here, does nginx look like it’s still doing the same thing, or has the error changed at all?

This should be done in conjunction with adding the web.socketed.template.yml template, did you do that?

2 Likes

Yes, I did.

I tried uninstalling and reinstalling NGIX and deleted the configuration file. However, the problem persists.

I will try to look for the NGIX errors listed and see what I find.

I solved the NGIX issue! :grinning:

In the /etc/nginx/sites-enabled/ folder there was some nonsense “ysystemctl status nginx” file. I deleted it.

Now, NGIX is working :muscle:

I’ll follow the riking’s instructions and let you know how it turns out.

1 Like

Ok, my discourse forum is up and running!

Unfortunately, the instructions don’t mention how to modify the settings for NGINX, which is running the website/WordPress.

It only says this: Make other NGINX “sites”, then link and enable them, as in the last step above.

I would really appreciate any tips on how to achieve this.

I installed wordpress according to this guide: How To Install WordPress With Docker Compose

Besides that, can you please confirm or deny my conclusions?

  1. NGINX (the one not in the container) is used as a reverse proxy.
  2. NGINX (the one not in the container) is referred to as “outer NGIX”.
  3. NGINX (the one not in the container) uses unix sockets instead of TCP ports for communication in the current setup.
  4. Discourse is a standalone application and therefore does not need to install its own NGIX webserver.

I apologize if I’m trying to verify obvious things. I just want to be 100% clear.

That’s pretty much it.

The discourse container includes nginx, rails, postgres and redis.

1 Like