AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1294138
Accepted
workfily app
workfily app
Asked: 2020-11-22 04:13:25 +0800 CST2020-11-22 04:13:25 +0800 CST 2020-11-22 04:13:25 +0800 CST

nginx更新配置文件后重启失败如何解决

  • 772

我在重新启动 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
server nginx aws
  • 1 1 个回答
  • 2765 Views

1 个回答

  • Voted
  1. Best Answer
    Danila Vershinin
    2020-11-22T04:37:57+08:002020-11-22T04:37:57+08:00

    您发布的输出中已经存在您的错误:

    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
    
    • 1

相关问题

  • 使用 dpkg 手动安装软件包是否会阻止未来的升级路径?

  • 如何从命令行刻录双层 dvd iso

  • 如果在服务器机器上运行 Ubuntu 桌面版,性能损失是多少?

  • 将桌面版剥离为服务器版的最简单方法是什么?

  • 如何与无头服务器进行图形交互?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve