我在重新启动 nginx 时遇到问题。我对 ubuntu 和 nginix 非常陌生。我正在尝试更改 nginx.conf 和 default.conf(新创建的)的配置。我的主要目标是将我的 MERN 应用程序部署到 Amazon Ec2
以下是我的配置
server {
#listen 80;
listen 80 default_server;
listen [::]:80 default_server;
server_name yourdomain.com;
access_log /home/ubuntu/client/server_logs/host.access.log main;
location / {
root /home/ubuntu/client/deploy;
index index.html index.htm;
try_files $uri /index.html;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
server_tokens off;
location ~ /\.ht {
deny all;
}
}
user ubuntu;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
client_body_buffer_size 100k;
client_header_buffer_size 1k;
client_max_body_size 100k;
large_client_header_buffers 2 1k;
client_body_timeout 10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;
server_tokens off;
#gzip on; on;
include /etc/nginx/conf.d/*.conf;
}
如果我尝试使用以下命令“sudo service nginx restart”重新启动 nginx,则会收到以下错误:
Job for nginx.service failed because the control process exited with an error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
由于我对 ubuntu 和 nginx 经验不足,我真的需要有人告诉我我做错了什么。或者有没有什么链接可以帮助我理解 nginx 配置。任何帮助都将不胜感激
systemctl status nginx.service 和 journalctl -xe 的输出”:
● 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 Sat 2020-11-21 12:23:42 UTC; 22s ago
Docs: man:nginx(8)
Process: 21094 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: [emerg] unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
The job identifier is 5626.
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: [emerg] unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
Nov 21 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: configuration file /etc/nginx/nginx.conf test failed
Nov 21 12:23:42 ip-172-31-23-90 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
我还使用“cat /var/log/nginx/error.log”检查了错误日志,并得到了以下内容:
ubuntu@ip-172-31-23-90:~$ cat /var/log/nginx/error.log
2020/11/21 07:47:49 [emerg] 18846#18846: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 07:54:57 [emerg] 18898#18898: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 07:59:37 [emerg] 18924#18924: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 11:09:41 [emerg] 20449#20449: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 11:20:03 [emerg] 20485#20485: unknown directive "er" in /etc/nginx/nginx.conf:1
2020/11/21 11:52:44 [emerg] 20822#20822: unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
2020/11/21 12:23:42 [emerg] 21094#21094: unknown directive "sten" in /etc/nginx/conf.d/default.conf:1
答案1
您发布的输出中已经存在错误:
11 月 21 日 12:23:42 ip-172-31-23-90 nginx[21094]: nginx: [emerg] /etc/nginx/conf.d/default.conf:1 中的未知指令“sten”
因此,请调查该文件/etc/nginx/conf.d/default.conf
并进行必要的更正。没有指令,当然sten
有指令 :)listen
不要每次都重启 NGINX,养成重新加载它的习惯(如果它已经在运行)。如果配置有错误,这将确保更好的正常运行时间。
sudo systemctl reload nginx
要检查终端中的配置问题,请运行:
nginx -t
要将完整的 NGINX 配置转储到终端(包含),请使用:
nginx -T