首页 > 解决方案 > nginx 配置错误:“[emerg] 文件意外结束,期待“;”或“}”

问题描述

我有以下 nginx 配置,在尝试启动 nginx 时遇到此错误:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

# server_tokens off;

    server_names_hash_bucket_size 164;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
            # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript 
text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;


upstream qe {
 server qe.domain.com:443;
}

upstream staging {
 server staging.domain.com:443;
}

upstream beta  {
 server mydomain.com:443;
 server mydomain-beta.com:443;
}

# map to different upstream backends based on header
map $http_x_server_select $pool {
 default "staging";
 qe "qe";
 beta "beta";
}

   server {
     listen 80;
 server_name 100.0.0.0 ec2.instance.compute-1.amazonaws.com;
 location / {
      proxy_pass https://$pool;

      #standard proxy settings
      proxy_set_header X-Real-IP $remote_addr;
      proxy_redirect off;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-NginX-Proxy true;
      proxy_connect_timeout 600;
      proxy_send_timeout 600;
      proxy_read_timeout 600;
      send_timeout 600;
 }
}
}

#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#

一切似乎都到位,但仍然看到这个错误。我错过了什么吗?这绝对不是花括号造成的,因为我有大括号。但不确定是什么导致了这个错误。

它在配置文件的最后一行给出了错误,其中我有一些注释配置,这是我安装 nginx 时默认出现的。但不要认为这是我尝试删除它的原因。

更新:所以我从配置文件中删除了所有内容,但仍然出现相同的错误。我很困惑现在发生了什么。

标签: nginx

解决方案


推荐阅读