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

How to resolve Nginx error 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 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

我刚刚添加了反向代理代码并上传到服务器。 这部分代码删不掉,不知道怎么解决。

我发现问题了,是windows记事本用BOM格式保存,用vscode重新select没有bom格式UTF-8.