I
I
Ivan Ivanov2021-03-08 12:47:13
Docker
Ivan Ivanov, 2021-03-08 12:47:13

How to make nginx work outside of localhost on docker?

I create a docker container, everything seems to be OK, however, despite the correct nginx configuration, the site opens only through localhost, and
test.conf does not open in the normal way:

server {
    index index.php;
    server_name test.dev;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/frontend/web;
    listen 80;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~* /\. {
        deny all;
    }
}

docker-compose:
nginx:
        # используем последний стабильный образ nginx
        image: nginx:latest
        # маршрутизируем порты
        ports:
            - "80:80"
            - "443:443"
        # монтируем директории, слева директории на основной машине, справа - куда они монтируются в контейнере
        volumes:
            - ./hosts:/etc/nginx/conf.d
            - ./www:/var/www
            - ./logs:/var/log/nginx
        # nginx должен общаться с php контейнером
        links:
            - php

The configuration is in the hosts folder, I added an entry to the hosts file (127.0.0.1 test.dev), when you open the desired page, it says "The site unexpectedly disconnected.", Nothing gets into the logs

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-03-08
@q2digger

Is nginx running right?
docker ps what does it say?
if you connect in a way that shows
curl -v test.dev
and
curl -v localhost

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question