我正在将容器化的nginx服务器部署到AWS上。但是,当我尝试访问它时,浏览器显示“无法连接”错误。日志文件给我错误:nginx: [emerg] unknown "server" variable
这是我的prod.conf文件:
server {
listen 80;
location / {
proxy_pass http://users:5000;
proxy_redirect default;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server-name;
}
}
这在Dockerfile-prod文件中:
FROM nginx:1.15.8-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY /prod.conf /etc/nginx/conf.d
compose-prod.yml文件:
version: '3.7'
services:
users:
build:
context: ./services/users
dockerfile: Dockerfile-prod
expose:
- '5000'
environment:
- FLASK_ENV=production
- APP_SETTINGS=project.config.ProductionConfig
- DATABASE_URL=postgres://postgres:postgres@users-db:5432/users_prod
- DATABASE_TEST_URL=postgres://postgres:postgres@users-db:5432/users_test
depends_on:
- users-db
users-db:
build:
context: ./services/users/project/db
dockerfile: Dockerfile
expose:
- '5432'
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
nginx:
build:
context: ./services/nginx
dockerfile: Dockerfile-prod
restart: always
ports:
- 80:80
depends_on:
- users
为什么给我这个错误?
答案 0 :(得分:0)
You should use $server_name
with underscore instead of $server-name
http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name