0

I run nginx with docker on my machine (localhost).

When I browse to localhost:8080 I expect to get "hello world", but I get "Welcome to nginx!" screen.

What I have missing in the configuration?

docker-compose.yml

web:
  image: nginx
  volumes:
    - ./example.com.conf:/etc/nginx/conf.d/example.com.conf
  ports:
    - '8080:80'

example.com.conf

server {
    location / {
        return 200 "hello world";
    }
}

I run the command:

docker-compose up

1 Answer 1

2

there is a /etc/nginx/conf.d/default.conf file exists inside the nginx image, which has

server {
  listen        80;
  server_name   default_server;
  ...
}

you either remove the default.conf file and properly setup your example.com.conf (listen to port, server_name etc...) or replace default.conf with your example.com.conf

you can replace by doing:

volumes:
  - ./example.com.conf:/etc/nginx/conf.d/default.conf
Sign up to request clarification or add additional context in comments.

3 Comments

But I don't want to override the config from nginx. because there may be important rules and behaviors I want them. and if I override with my own file then I lose everything from nginx.
why should you lose everything from nginx? the conf files are not being merged! they are "independent" sites. you need to setup your conf file properly, and if you still want to keep default.conf (which will still listen to port 80) you will need to let your exmaple.conf listen to some not an 80 port and request your website as http://...:8080 (if you will set the port to listen as 8080)
@JonSud first of all nothing bad happens when you replace default.conf file with your own, if you feel like so, don't use 80 port in your custom conf file, use some other port eg: 8080 and in the ports section change to "8080:8080"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.