Reputation: 525
I'm deploying containerized nginx server onto AWS. However, when I try to access it I get "Unable to connect" error from the browser. Log file is giving me error: nginx: [emerg] unknown "server" variable
This is my prod.conf file:
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;
}
}
this is in Dockerfile-prod file:
FROM nginx:1.15.8-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY /prod.conf /etc/nginx/conf.d
compose-prod.yml file:
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
Why is it giving me this error ?
Upvotes: 1
Views: 3863
Reputation: 708
You should use $server_name
with underscore instead of $server-name
http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name
Upvotes: 2