与当前时间相关,因此我正在为自己安装一个 mastodon 实例...
当我尝试重新启动 nginx 时,出现错误
root@instance-20221113-1925:/home/ubuntu# sudo systemctl restart nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.
这是日志(它说Nov 13 09:45:11 instance-20221113-1925 nginx[34044]: nginx: configuration file /etc/nginx/nginx.conf test failed
):
conf文件是(未编辑):
有经验的人能发现错误吗?谢谢!
答案1
也许您可以先删除 nginx,然后重新安装它。
列出与 nginx 相关的安装包,并将其删除。
dpkg --get-selections | grep nginx
sudo apt --purge remove nginx
sudo apt --purge remove nginx-common
sudo apt --purge remove nginx-core
并再次安装 nginx
sudo apt install nginx
现在,当我运行时systemctl status nginx
,服务处于活动状态。
成功启动 nginx
答案2
错误信息表明配置文件 /etc/nginx/sites-enabled/mastodon 第 25 行中 listen ... ssl 指令缺少 ssl_certificate 指令。
Nov 13 09:44:42 instance-20221113-1925 nginx[34033]: nginx: [emerg] no "ssl_certificate" is defined for the "listen ... ssl" directive in /etc/nginx/sites-enabled/mastodon:25
Nov 13 09:44:42 instance-20221113-1925 nginx[34033]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 13 09:44:42 instance-20221113-1925 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
尝试这个
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name your_domain.com;
ssl_certificate <<<<<<<</path/to/your/certificate.pem>>>>>>>;
ssl_certificate_key <<<<<<</path/to/your/private/key.pem;
# Additional SSL configurations can be added here
location / {
# proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_pass http://localhost:3000;
# proxy_buffering off;
# proxy_request_buffering off;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "upgrade";
}
}
}
请记住将 your_domain.com 替换为您的实际域名,并将 ssl_certificate 和 ssl_certificate_key 的路径更新为您的 SSL 证书和私钥文件的正确路径。