如何解决 Nginx 错误 nginx: [emerg] unknown directive "server" in conf:1?

我修改了 Nginx 的配置,并在重启 Nginx 时出现以下错误。

[root@host ~]# nginx -s reload
nginx: [emerg] unknown directive "server" in /usr/local/openresty/nginx/conf/vhost/www.xxx.com.conf:1

这是我的配置。我应该如何解决这个问题?

server {
    server_name www.xxx.com xxx.com;
    listen 80;
    listen     443;

          ssl        on;
          ssl_certificate         /data/https/domain.pem;
          ssl_certificate_key     /data/https/domain.key;

    root /data/wwwroot/www.xxx.com;
    index index.html index.htm index.php;

    #rewrite
    if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
    }

location ~ {
      proxy_pass http://127.0.0.1:8080;
      include proxy.conf;
    }

    location /nginx_status {
      stub_status on;
      access_log off;
      #allow 127.0.0.1;
     # deny all;
    }
    location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip: 9000;
    #fastcgi_pass 127.0.0.1: 9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /\.ht {
      deny all;
    }
    access_log off;

}

接下来,我使用了 -t 测试,结果如下。

[root@host ~]# nginx -t
nginx: [emerg] unknown directive "server" in /usr/local/openresty/nginx/conf/vhost/www.xxx.com.conf:1
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed

我只是添加了反向代理代码并上传到服务器。这部分代码不能删除,不知道如何解决这个问题。

点赞
用户6943518
用户6943518

我发现问题所在,是 windows 记事本保存时使用了 BOM 格式,使用 vscode 重新选择无 bom 格式的 UTF-8 即可。

2018-12-11 03:09:06