dongxing1965 2019-08-12 15:16
浏览 374

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用matlab 实现通信仿真
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
    • ¥20 5037端口被adb自己占了
    • ¥15 python:excel数据写入多个对应word文档
    • ¥60 全一数分解素因子和素数循环节位数
    • ¥15 ffmpeg如何安装到虚拟环境
    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
    • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件