簡體   English   中英

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

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

我已關注此網站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;

    }

}

我只是按照步驟操作,但無法成功運行。

我遇到了同樣的問題,我從網上復制/粘貼了配置代碼,並在那里復制了一些臟的EOL (行尾)字符。

編輯器沒有顯示它們,但nginx將它們視為指令。

剛剛刪除了每個EOL並再次添加。

聽起來你在這里做了一些復制和粘貼工作。 在行尾 (EOL) 中插入一些不可見的額外字符並不少見。 試試這個:

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

然后修復可能已被刪除並將受評論影響的任何中斷。

這對我有用。 希望它對你有用。

看起來 nginx 二進制文件是使用 --without-http_fastcgi_module 選項編譯的。這不是默認值。 嘗試下載或編譯不同的二進制文件。

嘗試跑步

nginx -V

(帶有大寫 V)以查看用於編譯 nginx 的選項。

我在 conf 文件的中間編輯了一些文本,nginx 開始在文件本身的開頭顯示此錯誤。 我復制了文件的內容,創建了一個新文件,將內容粘貼到那里,nginx 停止顯示此錯誤。

運行“sudo nginx -t”時,我遇到了類似錯誤消息“未知指令‘index.html’”的問題。 更正 index.html 中的 HTML 語法錯誤后,問題得到解決。

即使你錯過了一個分號,你也會遇到同樣的錯誤。

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

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

就我而言,我在 github 中存儲了配置文件nginx.conf 我已經對原始版本的代碼做了wget ,因此導致了這個錯誤。

后來,我克隆了我的存儲庫並使用了克隆中的nginx.conf文件,問題得到了解決。

真的沒看懂怎么回事
我已經“docker run”我的 nginx 1.14(debian:bullseye 的默認 apt)來提取它的默認 nginx.conf,目的是更新它,而不是將它用於我的 Dockerfile。

無論如何,在閱讀了該線程中的評論后,發現該文件是“UTF-16LE”……我不是真正的專家,但不是“UTF-8”。

解決為:

從容器內部看到的問題:

me@docker-nginx $ head nginx.conf 
��
user www-data:qgis;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
error_log /dev/stdout warn;


events {
    worker_connections 768;

me@docker-nginx  $ dos2unix nginx.conf 
dos2unix: converting UTF-16LE file nginx.conf to UTF-8 Unix format...

也解決了工作目錄:
IntelliJ IDEA:select 在“UTF-8”之后“轉換”
在此處輸入圖像描述

當我查看我的配置文件時我遇到了同樣的問題有一個語法錯誤所以這可能是問題檢查這個路徑

nano /etc/nginx/sites-available/example.com

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM