私は何をしたいですか?
最近、ローカルネットワークのサーバーとして使用するコンピュータにNixOSを設定しました。 nginxをhttpサーバーとして使用したいです。
私が試したこと
nginx
ファイルを/etc/nixos/configuration.nix
Environment.systempackagesセクション以下に配置しましたservices.nginx.enable=true
。ファイアウォールも無効になっています。ブラウザにサーバーのIPアドレスを入力すると、Webサービスは実行されていません。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;";
これにより問題が解決します。