Linux nginx: [emerg] /etc/nginx/sites-enabled/example.com:3 中的未知指令“”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19165976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:00:29  来源:igfitidea点击:

nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/example.com:3

linuxnginxraspberry-pihttpserverraspbian

提问by Confucius

I have followed this website http://raspberrypihelp.net/tutorials/24-raspberry-pi-webserverto setup the HTTP server nginx on my Raspberry Pi and try to setup a site call example.com. But when I run sudo service nginx restart, it said

我已经关注这个网站http://raspberrypihelp.net/tutorials/24-raspberry-pi-webserver在我的 Raspberry Pi 上设置 HTTP 服务器 nginx 并尝试设置一个站点调用example.com。但是当我跑的时候sudo service nginx restart,它说

Restarting nginx: nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/example.com:3

重新启动nginx:nginx:[emerg]未知指令“”在/etc/nginx/sites-enabled/example.com:3

Here is the code in example.com.

这是example.com 中的代码。

    server {

    server_name example.com 192.168.1.88;

    access_log /srv/www/example.com/logs/access.log;

    error_log /srv/www/example.com/logs/error.log;

    root /srv/www/example.com/public/;

    location / {

        index index.php index.html index.htm;

        try_files $uri $uri/ /index.php?$args;

    }

    location ~ \.php$ {

        include /etc/nginx/fastcgi_params;

        fastcgi_pass unix:/var/run/php5-fpm.sock;

        fastcgi_index index.php;

        fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public$fastcgi_script_name;

    }

    location /phpmyadmin {

        root /usr/share/;

        index index.php index.html index.htm;

        location ~ ^/phpmyadmin/(.+\.php)$ {

            try_files $uri =404;

            root /usr/share/;

            fastcgi_pass unix:/var/run/php5-fpm.sock;

            fastcgi_index index.php;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include /etc/nginx/fastcgi_params;

        }

        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {

            root /usr/share/;

        }

    }

    location /phpMyAdmin {

        rewrite ^/* /phpmyadmin last;

    }

}

I am just following the steps but it can't run successfully.

我只是按照步骤操作,但无法成功运行。

采纳答案by Andres Bott

I had the same problem which was that I copy/pasted the config code from the web and some dirty EOL(end of line) characters where there.

我遇到了同样的问题,我从网上复制/粘贴了配置代码和一些脏的EOL(行尾)字符。

The editor didn't show them, but nginxtreated them like a directive.

编辑器没有显示它们,而是nginx将它们视为指令。

Just deleted every EOLand added again.

刚刚删除了每一个,EOL然后再次添加。

回答by Ahmed

It looks like the nginx binary was compiled with --without-http_fastcgi_module option.This is not default. Try donwloading or compiling a different binary.

看起来 nginx 二进制文件是使用 --without-http_fastcgi_module 选项编译的。这不是默认值。尝试下载或编译不同的二进制文件。

Try running

尝试跑步

nginx -V

(with uppercase V) to see what options were used to compile the nginx.

(带有大写 V)以查看用于编译 nginx 的选项。

回答by Philll_t

It sounds like you did some copy and paste work here. It's not uncommon to snag some extra characters that are invisible at the end of line (EOL). Try this:

听起来你在这里做了一些复制和粘贴工作。在行尾 (EOL) 中插入一些不可见的额外字符并不少见。尝试这个:

Run your text through this tool: http://www.textfixer.com/tools/remove-line-breaks.php

通过此工具运行您的文本:http: //www.textfixer.com/tools/remove-line-breaks.php

then fix any breaks that may have been removed and will be affected by the comments.

然后修复可能已被删除并将受评论影响的任何中断。

This worked for me. Hope it works for you.

这对我有用。希望对你有效。

回答by shanmuga raja

I edited some text in the mid of the conf file and nginx started showing this error at the starting of the file itself. I copied the contents of the file, created a new file, pasted the contents there and nginx stopped showing this error.

我在 conf 文件的中间编辑了一些文本,nginx 开始在文件本身的开头显示此错误。我复制了文件的内容,创建了一个新文件,将内容粘贴到那里,nginx 停止显示此错误。

回答by Malathy

I faced similar issue with error message as "unknown directive 'index.html'" when running 'sudo nginx -t'. After correcting the HTML syntax errors in index.html, the issue was resolved.

运行“sudo nginx -t”时,我遇到了类似错误消息“未知指令‘index.html’”的问题。更正 index.html 中的 HTML 语法错误后,问题得到解决。