K
K
knowledge2019-01-10 16:17:44
Docker
knowledge, 2019-01-10 16:17:44

What's wrong with setting up a site in docker?

my docker starter project contains three small
docker-compose.yml files

version: '3'
services:
  web:
    image: nginx:1.15
    ports:
      - 8888:80
    volumes:
      - ./conf/doc.loc:/etc/nginx/sites-enabled/doc.loc
      - .:/app

doc.loc
server {
    listen 80;
    server_name doc.loc;
    index index.html index.php;
    root /app/public;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
  location / {
    try_files $uri $uri/ =404;
  }
}

and index.html
<h3>HELLO, WORLD</h3>
after running docker-compose up at localhost:8888/ the nginx start page opens
what did I forget to add?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-01-10
@knowledge

That's right, you have a site opened on localhost, which corresponds to the default config with server_name _;
, server_name doc.locthat is, if you access doc.loc:8888 after writing the "127.0.0.1 doc.loc" file in hosts, then it will open what you asked.
If you need it to work only on localhost, then just overwrite the default config:

...
    volumes:
      - ./conf/doc.loc:/etc/nginx/sites-enabled/default
...

in this case, the configuration should look like this:
docker-compose.yml
version: '3'
services:
  web:
    image: nginx:1.15
    ports:
      - 8888:80
    volumes:
      - ./conf/doc.loc:/etc/nginx/sites-enabled/default
      - .:/app

doc.loc
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    index index.html index.php;
    root /app/public;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
  location / {
    try_files $uri $uri/ =404;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question