MacOS M1 环境下的 Nginx + docker php-fpm7.4 部署fastadmin

Dokerfile

FROM php:7.4-fpm

# php 版本低于8的话安装swoole建议指定版本
RUN apt-get update && apt-get install -y \
    libfreetype6-dev \
    libjpeg62-turbo-dev \
    libpng-dev \
    libzip-dev \
    libssl-dev \
    git \
    unzip \
    && docker-php-ext-install -j$(nproc) mysqli pdo_mysql gd zip opcache bcmath \
    && docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ docker-php-ext-install gd \
    # && pecl install swoole-4.7.1 redis \            
    # && docker-php-ext-enable swoole redis \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

运行容器

docker run --name run-php-74-fpm -p 9002:9000
-v /Users/macos/Documents/Project/Env/Log/Php7:/var/www/html 
-v /Users/macos/Documents/Project/PHP:/usr/local/etc 
-v /Users/macos/Documents/Project/Env/Php7.4:/var/log/php
-d php-7.4-fpm

nginx配置

server {
        listen       80;
        server_name  local.admin.com;

        # php-fpm容器中的项目位置
        root /var/www/html/fastadmin/public;
        # aHjdVpIXqe为安装fastadmin生成的admin入口文件
        index index.php aHjdVpIXqe.php  index.html index.htm;
        client_max_body_size 120M;
        error_log /opt/homebrew/var/log/nginx/8090error.log;
        location / {

                if (!-e $request_filename) {
                        rewrite  ^(.*)$  /aHjdVpIXqe.php?s=/$1  last;
                        break;
                }

        }

        # 解决nginx访问静态资源404的问题,如下地址为宿主机项目地址
        location /assets {
           alias /Users/macos/Documents/Project/PHP/fastadmin/public/assets/;
        }



        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            # docker php-fpm容器运行的端口
            fastcgi_pass   127.0.0.1:9002;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

 

 

伪静态:

                if (!-e $request_filename) {
                        rewrite  ^(.+?\.php)(/.+)$ /后台.php?s=$2 last;
                        rewrite  ^(.*)$  /index.php?s=/$1  last;
                        break;
                }

 

posted @ 2023-07-01 22:18  php的自我修养  阅读(367)  评论(1编辑  收藏  举报