![nginx: [emerg] 不明なディレクティブ "http"](https://rvso.com/image/567675/nginx%3A%20%5Bemerg%5D%20%E4%B8%8D%E6%98%8E%E3%81%AA%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%86%E3%82%A3%E3%83%96%20%22http%22.png)
次のようなコードを作成しようとすると:
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 ファイルに配置します。