nginx:[emerg]未知指令“http”

nginx:[emerg]未知指令“http”

當我嘗試編寫這樣的程式碼時:

1. http {
2.    script
3.    server {
4.        ...
5.        location ...
6.    }
7. }

我收到錯誤:

nginx: [emerg] unknown directive "http" in /etc/nginx/conf.d/nginx.conf:1

當程式碼是這樣的時候:

1. server {
2.     ...
3.     location ...
4.     script
5. }
6. server {
7.     ...
8.     location ....
9.     script
10. }

……一切都很穩定。有人知道為什麼我不能使用嗎http

我在每個良好使用的範例中都看到可以看到http,但由於這個錯誤我無法很好地使用它。

nginx: nginx version: nginx/1.0.10
nginx: TLS SNI support enabled
nginx: configure arguments: --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6

答案1

/etc/nginx/nginx.conf 是帶有 http {} 的主設定文件,conf.d 中的文件被加載裡面那個塊,所以http已經在那裡了。

如果您想在 http 區塊中指定某些配置變量,請將其放入 conf.d 檔案中,並且沒有其他標籤包裹它。

相關內容