【问题标题】:nginx unexpected end of file, expecting ";" or "}" in /etc/nginx/sites-enabled/default:20 over Raspbiannginx 文件意外结束,期待“;”或 /etc/nginx/sites-enabled/default:20 中的 "}" 在 Raspbian 上
【发布时间】:2016-09-04 19:49:04
【问题描述】:

我是 nginx 和 Raspberry 的新手。

我使用

安装了 nginx

sudo apt-get 安装

那时一切都很好。当我尝试重新启动nginx时出现问题,它抛出了这个错误

nginx.service 的作业失败。有关详细信息,请参阅“systemctl status ngins.service”和“journaldtl -xn”

经过调查发现问题是下一个错误:

意外的文件结尾,期待“;”或 /etc/nginx/sites-enabled/default:20 中的“}”

我的默认文件是:

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
## 

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
    listen 80;
    server_name $domain_name;
    root /var/www;
    index index.html index.htm;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;



    # Make site accessible from http://localhost/
    server_name localhost;

    location /

我希望你能帮助我:)

【问题讨论】:

  • 你能在默认文件中显示第 20 行吗?
  • 正是下面的那一行 :location / 我试着写 ´}´ 但它不起作用。事实上我没有修改那个文件:/

标签: nginx raspbian raspberry-pi3


【解决方案1】:

更正你的 nginx 文件如下:

例如:

http {


       upstream api-app {
        .....................;   

        }
        ........................; 
        server {

              location / {
               ...................;
               proxy_set_header Host $host;
               proxy_cache_bypass $http_upgrade;

              }
        }

}

确保; 在行尾,{ ..} 正确。

【讨论】:

    【解决方案2】:

    @Thanh Nguyen Van 已经回答了。 location 必须在花括号中打开和关闭,然后在服务器端使用另一个花括号

    server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
    
        listen 80;
        server_name $domain_name;
        root /var/www;
        index index.html index.htm;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
    
        # Make site accessible from http://localhost/
        server_name localhost;
    
        location / {
    
        }
    }
    

    【讨论】:

      【解决方案3】:

      我有同样的问题。 确认在服务器块{...} 内的新添加行的末尾缺少;

      确保花括号和;全部到位

      【讨论】:

      • 谢谢。我只是错过了一个“;”在位置块 {} 内新添加的行的末尾。
      【解决方案4】:

      还要确保没有意外的引号(单引号或双引号)。当我使用 Docker 并将值作为 env var 传递时,我花了一段时间才弄清楚,所以它被错误地引用了。

      所以,这将是一个错误的位:

      upstream backend {
          "server localhost:9000;"
      }
      

      这是正确的:

      upstream backend {
          server localhost:9000;
      }
      

      【讨论】:

        【解决方案5】:

        我的问题是由于缺少 ; 作为命令行参数之一的一部分。

        这里是我的日志供参考:

        2020/08/11 17:19:25 [emerg] 1#1: unexpected end of parameter, expecting ";" in command line
        nginx: [emerg] unexpected end of parameter, expecting ";" in command line
        

        我的错误是我通过 docker 使用以下 CMD 开始 nginx

        CMD ["nginx", "-g", "daemon off"]
        

        我错过了尾随的;。我应该有的是:

        CMD ["nginx", "-g", "daemon off;"]
        

        以防万一它帮助其他人。

        【讨论】:

        • 哎呀,很容易错过。我正在倾注我的配置,但找不到它。就是这样。
        猜你喜欢
        • 2020-02-17
        • 1970-01-01
        • 2015-11-22
        • 2015-05-24
        • 2013-10-10
        • 2021-06-26
        • 2017-07-24
        • 2016-01-05
        • 1970-01-01
        相关资源
        最近更新 更多