K
K
knowledge2019-01-05 17:55:25
Docker
knowledge, 2019-01-05 17:55:25

How to set up a simple site with nginx using docker-compose?

Site structure

docker:
    conf:
        myapp.loc
public:
    index.html
docker-compose.yml

myapp.loc
server {
  listen 80;

    server_name myapp.loc;
    index index.php index.html;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;

    root /app/public;

  location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    try_files $uri $uri/ =404;
  }
}

docker-compose.yml
version: "2"
services:
  web:
      image: nginx:1.15
      ports:
        - "9090:80"
      volumes:
      - ./docker/conf/myapp.loc:/etc/nginx/sites-enabled/myapp.loc
      - .:/app

index.html
<h4>HELLO, WORLD</h4>
I enter localhost:9090 in the browser
, the nginx start page opens,
what am I doing wrong?
if the root directory is replaced with /usr/share/nginx/html/
and in myapp.loc enter /usr/share/nginx/html/public
then localhost:9090 will answer 403 forbidden
localhost:9090/public will open what you need, from here we can conclude that myapp.loc is not being read at all

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2019-01-05
@Zarom

listen 80 default_server;
Or set up your working machine so that the site is opened by myapp.loc:9090 - you specify thatserver_name myapp.loc;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question