【问题标题】:nginx: [emerg] unknown directive " " in /etc/nginx/sites-enabled/example.com:3nginx:[emerg] 未知指令“”在 /etc/nginx/sites-enabled/example.com:3
【发布时间】:2013-10-10 13:14:45
【问题描述】:

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

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

这是 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;

    }

}

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

【问题讨论】:

  • 安装的是什么版本的nginx?根据这个网站,您使用 apt-get 获得的版本存在一些问题。 virtualitblog.blogspot.nl/2013/05/… 我可以建议添加 nginx.org apt 存储库并重新安装 nginx 吗?你也可以运行:ldd /usr/sbin/nginx 并将结果发布到 gist.github.com 的某个地方吗?
  • 我已经使用/usr/sbin/nginx -t -v 来检查我使用的是 nginx/1.2.1,当我运行 sudo apt-get install nginx 时,我已经按照 http://nginx.org/en/linux_packages.html 将其添加到 apt sources.list 中返回 nginx 已经是最新版本了。。有一件事我忘了说,我可以去http://127.0.0.1/我可以看到默认站点(/usr/share/nginx/www/index.html)。
  • 请选择最适合您的答案。谢谢。

标签: linux nginx raspberry-pi httpserver raspbian


【解决方案1】:

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

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

刚刚删除了每个EOL 并再次添加。

【讨论】:

  • 我遇到了同样的错误。没想到这是一开始的错误。我尝试将我的文本复制粘贴到记事本中。试图使用在线工具来清理我的文本。但是窗户一直在拧。我通过启动 Linux VM 并创建相同的文档来解决它。然后我将文件传输到 Windows 并将其用于我的脚本。有效。我无法区分linux文件和windows文件之间的区别。但它为我解决了这个问题。
  • 所以windows中的行尾是CRLF或\r\n。使用 nginx,解析器不理解 windows CRLF,而只理解 LF (\n)。使用编辑器删除它们就可以了。
【解决方案2】:

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

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

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

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

【讨论】:

    【解决方案3】:

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

    尝试运行

    nginx -V
    

    (带大写 V)查看编译 nginx 时使用了哪些选项。

    【讨论】:

    • 不错的方法,但是如何使用必要的选项重新编译?
    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

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

      【讨论】:

        【解决方案6】:

        即使你错过了一个分号,你也会遇到同样的错误。

        // Missed semicolon
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock
        
        // With semicolon
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        

        【讨论】:

          【解决方案7】:

          就我而言,我在 github 中有存储配置文件 nginx.conf。我对原始版本的代码做了wget,因此导致了这个错误。

          后来,我克隆了我的存储库并使用了克隆中的nginx.conf 文件,问题得到了解决。

          【讨论】:

            猜你喜欢
            • 2020-02-17
            • 2021-06-26
            • 2013-10-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-08-30
            • 2017-11-10
            • 2020-04-09
            相关资源
            最近更新 更多