CRMEB PHP多店户版DOCKER部署

#具体操作参考上一篇#

这里只列出相关文件内容,以供参考,有不对之处请指正。

Dockerfile, 这个文件没有改变。

# 使用官方的Ubuntu 24.04镜像作为基础镜像
FROM ubuntu:24.04

# 设置环境变量以避免交互式配置工具
ENV DEBIAN_FRONTEND=noninteractive

# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
    echo "Asia/Shanghai" > /etc/timezone

# 更新包列表并安装必要的软件包
RUN apt-get update && \
    apt-get install -y software-properties-common ca-certificates nginx supervisor && \
    add-apt-repository ppa:ondrej/php && \
    apt-get update && \
    apt-get install -y \
        php7.4 \
        php7.4-cli \
        php7.4-fpm \
        php7.4-dev \
        php7.4-bcmath \
        php7.4-soap \
        php7.4-intl \
        php7.4-readline \
        php7.4-ldap \
        php7.4-msgpack \        
        php7.4-igbinary \
        php7.4-mysql \
        php7.4-pgsql \
        php7.4-gd \
        php7.4-imagick \
        php7.4-curl \
        php7.4-mbstring \
        php7.4-xml \
        php7.4-zip \
        php7.4-redis \
        php7.4-memcached \
        php7.4-amqp \
        git \
        unzip \
        curl \
    && pecl install swoole-4.8.13 \
    && echo "extension=swoole.so" > /etc/php/7.4/mods-available/swoole.ini \
    && phpenmod swoole \
    && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
    && apt-get -y autoremove \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY swoole_loader74.so /usr/lib/php/20190902
RUN echo "extension=swoole_loader74.so" > /etc/php/7.4/mods-available/swoole_loader.ini \
    && phpenmod swoole_loader 

# 确保目录存在
RUN mkdir -p /run/php \
    && chown -R www-data:www-data /run/php

# 设置工作目录
WORKDIR /var/www/html

# 设置权限
RUN chown -R www-data:www-data /var/www/html

# 配置 Nginx
COPY nginx.conf /etc/nginx/nginx.conf
COPY default /etc/nginx/sites-available/default

# 配置 Supervisor
COPY supervisord.conf /etc/supervisord.conf

# 暴露默认的PHP-FPM端口
EXPOSE 80

# 启动 Supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

nginx.conf,同样没有修改。

user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

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

        ##
        # Gzip Settings
        ##

        gzip on;

        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
#
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

default, 去掉了没用的内容,修改了多店版相关设置。

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
        listen 80;
        listen [::]:80;

        root /var/www/html/public;

        # Add index.php to the list if you are using PHP
        index index.php;

        server_name localhost;

        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Content-Type-Options "nosniff";

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

#PROXY-START/
location  ~* \.(php|jsp|cgi|asp|aspx)$
{
    proxy_pass http://127.0.0.1:20699;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
}
location /
{
    if (!-e $request_filename) {
         proxy_pass http://127.0.0.1:20699;
    }
    proxy_http_version 1.1;
    proxy_read_timeout 360s;   
    proxy_redirect off; 
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache

       add_header Cache-Control no-cache;
    expires 12h;
}
#PROXY-END/


        charset utf-8;

        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }

        error_page 404 /index.php;

        access_log /var/log/nginx/app_access.log;
        error_log /var/log/nginx/app_error.log;

}

supervisord.conf, 合并了配置文件,swoole的启动参数做了调整。多店版的think-swoole的参数跟多商户版不一样,不需要restart参数。增加了supervisorctl的设置,但似乎没什么用,依然不能用这个命令。

[supervisord]
nodaemon=true
logfile=/var/log/nginx/supervisord.log
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

[program:crmeb-queue]
command=/usr/bin/php7.4 /var/www/html/think queue:listen --tries=2
autostart=true
autorestart=true
stdout_logfile=/var/log/nginx/crmeb-queue.stdout.log
stderr_logfile=/var/log/nginx/crmeb-queue.stderr.log

[program:crmeb-swoole]
command=/usr/bin/php7.4 /var/www/html/think swoole
autostart=true
autorestart=true
stdout_logfile=/var/log/nginx/crmeb-swoole.stdout.log
stderr_logfile=/var/log/nginx/crmeb-swoole.stderr.log

[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
stdout_logfile=/var/log/nginx/nginx.stdout.log
stderr_logfile=/var/log/nginx/nginx.stderr.log

swoole_loader74.so, 这个文件不能少,放在同一个目录内。

执行编译命令:

docker build -t crmeb_multi:7.4 .

没报错就是成功了。可以用 docker images -a 来确认下。

最后,

创建容器:

docker run -itd --name=crmeb-multi  -v /var/www/CRMEB_MULTI_v3.1.1:/var/www/html -v /data/log/crmeb_multi:/var/log/nginx -p 81:80 crmeb_multi:7.4

确认:

docker ps -a 

看到crmeb-multi在运行。

主机上用nginx做反向代理:

    location / {
        proxy_pass   http://127.0.0.1:81;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

完成