Answer a question

I'm trying to setup a server with nginx and docker-compose, but I get these errors every time I try 'docker-compose up':

webserver | 2019/06/10 13:04:16 [emerg] 1#1: "http" directive is not allowed here in /etc/nginx/conf.d/default.conf:1
webserver | nginx: [emerg] "http" directive is not allowed here in /etc/nginx/conf.d/default.conf:1

I've tried wrapping all up with html {}, removing server {}, another port instead of 80...

nginx Dockerfile

FROM nginx

COPY default.conf /etc/nginx/conf.d/default.conf

default.conf

server {
    listen       80;
    server_name  localhost;

    location / {
        proxy_set_header  Host $host;
        proxy_set_header  X-Real-IP $remote_addr;
        proxy_pass http://app:8080/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

Answers

This happens when you are trying to overwrite the default nginx config file which does not accept some root properties like http, user. If you need those extra configurations you can try copying what you have to /etc/nginx/nginx.conf

So instead of this: COPY default.conf /etc/nginx/conf.d/default.conf

Do this: COPY nginx.conf /etc/nginx/nginx.conf

Note: By copying to the /etc/nginx/conf.d/, you will be overwriting the default config.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐