首页 > 解决方案 > 如何解决 Nginx 错误 nginx: [emerg] conf:1 中的未知指令“server”?

问题描述

我改了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

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

标签: nginxnginx-config

解决方案


发现问题,是windows记事本用BOM格式保存的,用vscode重新选择no bom格式UTF-8。


推荐阅读