nixos에서 nginx 실행

nixos에서 nginx 실행

내가 뭘 하려는 거지?

최근에 로컬 네트워크의 서버로 사용하려는 컴퓨터에 NixOS를 설정했습니다. nginx를 http 서버로 사용하고 싶습니다.

내가 시도한 것

nginx파일을 /etc/nixos/configuration.nixEnvironment.systempackages 섹션 이하 에 넣었습니다 services.nginx.enable=true. 방화벽도 비활성화되어 있습니다. 이제 브라우저에 서버의 IP 주소를 입력하면 웹 서비스가 실행되고 있지 않습니다. nginx이제 터미널 에 입력하면 다음과 같은 결과가 나타납니다.

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

이런 일은 이후에도 발생합니다 sudo fuser -k 80/tcp. 나는 또한 이것을 추가하려고 시도했습니다.

  services.nginx = {
    enable = true;
    recommendedProxySettings = true;
    recommendedTlsSettings = true;
    virtualHosts."localhost" = {
      locations."/var/html/".proxyPass = "http://localhost:8000";
    };
    appendHttpConfig = "listen 127.0.0.1:80";  
  };

내 nixos 구성(일부 행 주석 처리 포함)이지만 실행 시 nixos-rebuild switch출력은 다음과 같습니다.

Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
warning: error(s) occurred while switching to the new configuration

산출systemctl status nginx.service

● nginx.service - Nginx Web Server
     Loaded: loaded (/nix/store/brnpdnprg2x0iapkiilzdl4avg8zfsbh-unit-nginx.service/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-11-15 02:35:09 CET; 3min 59s ago
    Process: 14637 ExecStartPre=/nix/store/vpjfv9bzqrx1klbghh5vn5p9g8w0bs9n-unit-script-nginx-pre-start/bin/nginx-pre-start (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 47ms

Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Scheduled restart job, restart counter is at 5.
Nov 15 02:35:09 srv0 systemd[1]: Stopped Nginx Web Server.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Start request repeated too quickly.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 15 02:35:09 srv0 systemd[1]: Failed to start Nginx Web Server.

출력 journalctl -xe:

● nginx.service - Nginx Web Server
     Loaded: loaded (/nix/store/brnpdnprg2x0iapkiilzdl4avg8zfsbh-unit-nginx.service/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-11-15 02:35:09 CET; 6min ago
    Process: 14637 ExecStartPre=/nix/store/vpjfv9bzqrx1klbghh5vn5p9g8w0bs9n-unit-script-nginx-pre-start/bin/nginx-pre-start (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
        CPU: 47ms

Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Scheduled restart job, restart counter is at 5.
Nov 15 02:35:09 srv0 systemd[1]: Stopped Nginx Web Server.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Start request repeated too quickly.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 15 02:35:09 srv0 systemd[1]: Failed to start Nginx Web Server.

[xoxulux@srv0:~]$ journalctl -xe
░░ The job identifier is 69422.
Nov 15 02:34:59 srv0 nginx-pre-start[14638]: nginx: [emerg] unexpected "}" in /nix/store/ncxk0zwr2y14k8424dwkz4il2qgh0d9h-nginx.conf:49
Nov 15 02:34:59 srv0 nginx-pre-start[14638]: nginx: configuration file /nix/store/ncxk0zwr2y14k8424dwkz4il2qgh0d9h-nginx.conf test failed
Nov 15 02:34:59 srv0 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ An ExecStartPre= process belonging to unit nginx.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Nov 15 02:34:59 srv0 systemd[1]: nginx.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Nov 15 02:34:59 srv0 systemd[1]: Failed to start Nginx Web Server.
░░ Subject: A start job for unit nginx.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit nginx.service has finished with a failure.
░░ 
░░ The job identifier is 69422 and the job result is failed.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Scheduled restart job, restart counter is at 5.
░░ Subject: Automatic restarting of a unit has been scheduled
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ Automatic restarting of the unit nginx.service has been scheduled, as the result for
░░ the configured Restart= setting for the unit.
Nov 15 02:35:09 srv0 systemd[1]: Stopped Nginx Web Server.
░░ Subject: A stop job for unit nginx.service has finished
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A stop job for unit nginx.service has finished.
░░ 
░░ The job identifier is 69482 and the job result is done.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Start request repeated too quickly.
Nov 15 02:35:09 srv0 systemd[1]: nginx.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Nov 15 02:35:09 srv0 systemd[1]: Failed to start Nginx Web Server.d
░░ Subject: A start job for unit nginx.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit nginx.service has finished with a failure.
░░ 
░░ The job identifier is 69482 and the job result is failed.

저는 NixOS를 처음 접해서 기본적인 실수를 하고 있는 것일 수도 있는데 어떻게 해야 합니까?

추가 정보

콘텐츠 /nix/store/ncxk0zwr2y14k8424dwkz4il2qgh0d9h-nginx.conf:

pid /run/nginx/nginx.pid;
error_log stderr;
daemon off;
events {
}
http {
        # The mime type definitions included with nginx are very incomplete, so
        # we use a list of mime types from the mailcap package, which is also
        # used by most other Linux distributions by default.
        include /nix/store/r2wvgnr54vmwnjvzyqdixv8xbn362jgh-mailcap-2.1.48/etc/nginx/mime.types;
        include /nix/store/d7ccapjb8fpjiryk8lc1sfn8gar9fbhl-nginx-1.18.0/conf/fastcgi.conf;
        include /nix/store/d7ccapjb8fpjiryk8lc1sfn8gar9fbhl-nginx-1.18.0/conf/uwsgi_params;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
        # Keep in sync with https://ssl-config.mozilla.org/#server=nginx&config=intermediate
        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:10m;
        # Breaks forward secrecy: https://github.com/mozilla/server-side-tls/issues/135
        ssl_session_tickets off;
        # We don't enable insecure ciphers by default, so this allows
        # clients to pick the most performant, per https://github.com/mozilla/server-side-tls/issues/260
        ssl_prefer_server_ciphers off;
        # OCSP stapling
        ssl_stapling on;
        ssl_stapling_verify on;
        proxy_redirect          off;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_http_version      1.0;
        include /nix/store/vzv0ly0l1kv8r1drdg86w9wlipcwdxnw-nginx-recommended-proxy-headers.conf;
        # $connection_upgrade is used for websocket proxying
        map $http_upgrade $connection_upgrade {
                default upgrade;
                ''      close;
        }
        client_max_body_size 10m;
        server_tokens off;
        server {
                listen 0.0.0.0:80 ;
                listen [::]:80 ;
                server_name localhost ;
                location /var/html/ {
                        proxy_pass http://localhost:8000;
                        include /nix/store/vzv0ly0l1kv8r1drdg86w9wlipcwdxnw-nginx-recommended-proxy-headers.conf;
                }
        }
        listen 127.0.0.1:80
}

답변1

Nov 15 02:34:59 srv0 nginx-pre-start[14638]: nginx: [emerg] unexpected "}" in /nix/store/ncxk0zwr2y14k8424dwkz4il2qgh0d9h-nginx.conf:49
Nov 15 02:34:59 srv0 nginx-pre-start[14638]: nginx: configuration file /nix/store/ncxk0zwr2y14k8424dwkz4il2qgh0d9h-nginx.conf test failed
N

문제는 49행을 보면 다음과 같다는 것입니다.

listen 127.0.0.1:80

줄 끝에 ; 이 누락되어 있음을 알 수 있습니다. 그것이 문제이다. Configuration.nix 파일을 보면 다음을 볼 수 있습니다.

    appendHttpConfig = "listen 127.0.0.1:80";  

;줄 끝에 추가 하지 못했습니다 . 다음과 같이 변경해 보세요.

    appendHttpConfig = "listen 127.0.0.1:80;";

이렇게 하면 문제가 해결될 것입니다.

관련 정보