program story

nginx : [emerg] "server"지시문은 여기에서 허용되지 않습니다.

inputbox 2020. 10. 24. 10:14
반응형

nginx : [emerg] "server"지시문은 여기에서 허용되지 않습니다.


nginx를 재구성했지만 다음 구성을 사용하여 다시 시작할 수 없습니다.

conf :

server {
listen 80;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}


server {
listen 80;
server_name example.com;

access_log /var/log/nginx/access.log;
error_log  /var/log/nginx/error.log;

location /robots.txt {
    alias /path/to/robots.txt;
    access_log off;
    log_not_found off;
}

location = /favicon.ico { access_log off; log_not_found off; }

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_connect_timeout 30;
    proxy_read_timeout 30;
    proxy_pass http://127.0.0.1:8000;
}

location /static {
    expires 1M;
    alias  /path/to/staticfiles;
}
}

sudo nginx -c conf -t구성을 테스트하기 위해 실행 한 후 다음 오류가 반환됩니다. 실제로 문제가 무엇인지 파악할 수 없습니다.

nginx: [emerg] "server" directive is not allowed here in    /etc/nginx/sites-available/config:1
nginx: configuration file /etc/nginx/sites-available/config test failed

이것은 nginx구성 파일 이 아닙니다 . 그것은이다 부분nginx구성 파일.

nginx(보통라는 구성 파일 nginx.conf)과 같이 표시됩니다

events {
    ...
}
http {
    ...
    server {
        ...
    }
}

server블록은 내에 봉입 http블록.

종종 구성은 include지시문을 사용하여 추가 조각을 가져와 (예 : sites-enabled디렉토리에서) 여러 파일에 분산 됩니다.

Use sudo nginx -t to test the complete configuration file, which starts at nginx.conf and pulls in additional fragments using the include directive. See this document for more.


Example valid nginx.conf for reverse proxy; In case someone is stuck like me

events {
  worker_connections  4096;  ## Default: 1024
}
http {
 server {
   listen 80;
   listen [::]:80;

   server_name 10.x.x.x;

   location / {
       proxy_pass http://10.y.y.y:80/;
       proxy_set_header Host $host;
   }
 }
}

and you can serve it up in docker too

 docker run --name nginx-container --rm --net=host   -v /home/core/nginx/nginx.conf:/etc/nginx/nginx.conf nginx

참고URL : https://stackoverflow.com/questions/41766195/nginx-emerg-server-directive-is-not-allowed-here

반응형