Docker nginx + php-fpm配置主机?

I am trying to set up a work environment for myself. I can’t get to the server through the name specified in hosts file.

docker-compose.yml:

version: '2'

services:
    nginx:
        image: nginx:latest
        ports:
            - "80:80"
            - "443:443"
        volumes:
            - ./hosts:/etc/nginx/conf.d
            - ./www:/var/www
            - ./logs:/var/log/nginx
        links:
            - php
    php:
        build: ./images/php
        links:
            - mysql
        volumes:
            - ./www:/var/www
    mysql:
        image: mysql:8
        ports:
            - "3306:3306"
        volumes:
            - ./mysql:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: secret

php dockerfile:

FROM php:7.1-fpm

RUN apt-get update && apt-get install -y \
        curl \
        wget \
        git \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mcrypt mbstring mysqli pdo_mysql zip \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd


RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

ADD php.ini /usr/local/etc/php/conf.d/40-custom.ini

WORKDIR /var/www

CMD ["php-fpm"]

./hosts/hello-dev.conf:

server {
    server_name hello.dev;
    listen 80;
    index index.php;
    set $MAGE_ROOT /var/www/hello.dev;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root $MAGE_ROOT;

    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;
    }
}

hosts: 127.0.0.1 hello.dev

Tell me what you can try to do in this situation? If I go to the address http://127.0.0.1 it opens the site, but I need to be able to create several configs with different names.

doumengbai2031
doumengbai2031 我想你可能需要在你的HOSTS文件中添加hello.dev指向127.0.0.1(如果在Windows上,如果在另一个操作系统上可能是类似的解决方案)。
大约一年之前 回复
douwen1213
douwen1213 我无法通过hello.dev访问服务器
大约一年之前 回复
duancai7568
duancai7568 你是什​​么意思“我无法进入服务器”?
大约一年之前 回复
dthyxna3894
dthyxna3894 “用不同的名字创建几个配置”是什么意思?
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐