我正在尝试使用 nginx 和 docker-compose 设置服务器,但每次尝试“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
Run Code Online (Sandbox Code Playgroud)
我尝试用 html {} 包装所有内容,删除服务器 {},另一个端口而不是 80...
nginx Dockerfile
FROM nginx
COPY default.conf /etc/nginx/conf.d/default.conf
Run Code Online (Sandbox Code Playgroud)
默认配置文件
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;
}
}
Run Code Online (Sandbox Code Playgroud)
当您尝试覆盖默认的 nginx 配置文件时会发生这种情况,该文件不接受某些根属性,例如http, user。如果您需要这些额外的配置,您可以尝试复制您需要的内容/etc/nginx/nginx.conf
所以代替这个:COPY default.conf /etc/nginx/conf.d/default.conf
做这个:COPY nginx.conf /etc/nginx/nginx.conf
注意:通过复制到
/etc/nginx/conf.d/,您将覆盖默认配置。
| 归档时间: |
|
| 查看次数: |
7201 次 |
| 最近记录: |