NGINX 시작 실패

안녕하세요, 여러분!

서브도메인에 Discourse를 설치하려고 하고 있습니다.

주 도메인은 docker-compose를 사용하여 구축된 WordPress가 실행 중입니다.

서브도메인과 도메인은 동일한 VPS 서버를 사용하고 있습니다.

설치 과정에서는 다음 가이드를 따랐습니다: https://meta.discourse.org/t/run-other-websites-on-the-same-machine-as-discourse/17247

불행히도 NGINX를 시작할 수 없습니다. systemctl status nginx 명령을 실행하면 다음 메시지가 표시됩니다:

× 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.

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

여러 번 확인해 보았지만, 오류가 어디서 나는지 파악하지 못하고 있습니다.

죄송합니다. 저는 Linux / NGINX / Docker 관련해서는 초보입니다. 조언을 주시면 감사하겠습니다. 감사합니다.

해당 머신에서 포트 80을 점유하고 있는 다른 웹 서버가 있나요?

app.yml에서 포트를 변경하여 Discourse가 NGINX가 사용하려는 포트를 사용하지 못하게 했나요?

이것은 DNS, HTTPS 및 인증서, nginx, 리버스 프록시, docker, 라우팅에 대한 이해가 필요한 고급 설정입니다.

앞서 언급했듯이, 워드프레스는 메인 도메인에서 실행되고 있습니다.

제 이해가 맞다면, 다른 NGINX는 워드프레스와 함께 컨테이너 내에서 작동하는 것입니다.

다음 튜토리얼을 따랐습니다: How To Install WordPress With Docker Compose | DigitalOcean

netstat -tulnp 명령을 실행하면 다음과 같은 결과가 나옵니다:

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

설명이 주석 처리하라고 해서 그렇게 했습니다:

## 이 컨테이너는 어떤 TCP/IP 포트를 노출해야 하나요?
## Apache나 nginx 같은 다른 웹서버와 포트를 공유하려면
## 자세한 내용은 https://meta.discourse.org/t/17247 을 참고하세요
expose:
  # - "80:80"   # http
  # - "443:443" # https

DNS 레코드, https, 인증서는 잘 알고 있습니다. 나머지 부분만 제게는 새로운 내용입니다.

걱정 마세요. 구글링하는 법은 알았고, 저는 빠른 학습자입니다 :wink:

이 작업을 시작하기 전에, Discourse를 추가하려는 NGINX 리버스 프록시가 이미 정상적으로 작동 중이었나요?

아니면 Apache/WordPress가 이전에 실행 중이었기 때문에 포트 80을 사용 중인가요?

아, docker-proxy가 포트 80을 사용 중인 것 같은데, 워드프레스를 docker-proxy 뒤에 두었나요?

docker ps를 실행해서 도커 컨테이너를 확인해 보세요.

말씀드린 대로, 다른 NGIX(WordPress용)가 MySQL과 WordPress와 함께 컨테이너 안에서 작동한다고 생각합니다.

docker ps 명령을 실행하면 다음과 같은 결과가 나옵니다:

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

외부 nginx가 부팅되지 않는 이유는 포트가 내부 nginx에 의해 이미 사용되고 있기 때문입니다. 아마도 해당 컨테이너를 종료하고, WordPress용 설정을 외부 nginx 계층으로 이전해야 할 것입니다.

또한, 이는 별도의 컨테이너입니다. nginx는 MySQL과 WordPress와 분리되어 있습니다.

웹서버(NGIX 컨테이너)를 종료한 후 외부 NGIX를 시작해 보았지만 여전히 작동하지 않습니다.

맞습니다. 제 실수입니다. 언급된 모든 앱이 하나의 컨테이너 안에 있다고 생각했습니다.

하나의 컨테이너 = 하나의 애플리케이션/프로그램 :wink:

지금 docker ps와 netstat -tulnp의 상태는 어떻게 되나요?

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

여기서 제가 더 할 수 있는 일은 많지 않은데, nginx가 여전히 같은 일을 하고 있는 건지, 아니면 오류가 조금이라도 바뀌었는지 확인해 줄 수 있나요?

web.socketed.template.yml 템플릿을 추가하는 것과 함께 수행해야 하는데, 그렇게 하셨나요?

네, 그렇게 했습니다.

NGINX를 삭제한 후 다시 설치하고 구성 파일도 지웠습니다. 하지만 문제는 여전히 남아 있습니다.

나중에 NGINX에서 나열된 오류를 찾아보고 어떤 문제가 있는지 확인해 보겠습니다.

NGIX 문제를 해결했습니다! :grinning:

/etc/nginx/sites-enabled/ 폴더에 "ysystemctl status nginx"라는 이상한 파일이 하나 있었습니다. 삭제했습니다.

이제 NGIX가 정상적으로 작동합니다 :muscle:

riking님의 지시를 따르고, 결과가 어떻게 나올지 알려드리겠습니다.

드디어 내 Discourse 포럼이 성공적으로 구동되고 있습니다!

불행히도 설명서에는 웹사이트/WordPress를 실행 중인 NGINX의 설정을 어떻게 수정하는지에 대한 언급이 없습니다.

아래의 마지막 단계와 마찬가지로 다른 NGINX "사이트"를 만든 후 링크를 걸고 활성화하라는 내용만 나와 있습니다.

이 작업을 수행하는 방법에 대한 팁을 정말로 감사히 여깁니다.

저는 이 가이드에 따라 WordPress를 설치했습니다: How To Install WordPress With Docker Compose

그리고 이 기회에 제 결론이 맞는지 확인해 주시거나, 틀렸다고 알려주실 수 있을까요?

  1. 컨테이너 외부의 NGINX는 리버스 프록시로 사용됩니다.
  2. 컨테이너 외부의 NGINX는 "외부 NGINX(outer NGINX)"라고 불립니다.
  3. 컨테이너 외부의 NGINX는 현재 설정에서 TCP 포트 대신 유닉스 소켓을 사용하여 통신합니다.
  4. Discourse는 독립형 애플리케이션이므로 자체 NGINX 웹서버를 설치할 필요가 없습니다.

분명한 것을 확인하려고 해서 죄송합니다. 다만 100% 명확하게 알고 싶을 뿐입니다.

대충 이 정도입니다.

discourse 컨테이너에는 nginx, rails, postgres, redis가 포함되어 있습니다.