diff --git a/README.md b/README.md index e292800..70f8c46 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ -# dnmp -Docker + nginx + MySQL + PHP +# DNMP + +Learn more about how DNMP can streamline your development process and make your projects more efficient. + diff --git a/mysql/.env b/mysql/.env index 4a0c246..c0aa000 100644 --- a/mysql/.env +++ b/mysql/.env @@ -1,2 +1,2 @@ TZ=Asia/Shanghai -MYSQL_ROOT_PASSWORD=9N7DahRCqinY \ No newline at end of file +MYSQL_ROOT_PASSWORD=root3306 \ No newline at end of file diff --git a/nginx/conf/nginx.conf b/nginx/conf/nginx.conf index 6d85642..c8c8e65 100644 --- a/nginx/conf/nginx.conf +++ b/nginx/conf/nginx.conf @@ -89,7 +89,7 @@ http { open_file_cache_min_uses 2; open_file_cache_errors on; - + # default site server { listen 80; server_name localhost; @@ -98,23 +98,16 @@ http { #access_log logs/host.access.log main; - location / { - root html; - index index.html index.htm; + root /var/www/html/default; + index index.php index.html index.htm; + + # PHP 配置 + location ~ [^/]\.php(/|$) { + include fastcgi_params; + fastcgi_pass 127.0.0.1:9074; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } - # phpmyadmin - location /phpmyadmin { - alias /var/www/html/phpMyAdmin/; # 将 /path/to/phpmyadmin 替换为你的实际目录 - index index.php index.html index.htm; - - # PHP 配置 - location ~ /phpmyadmin/.+\.php$ { - include fastcgi_params; - fastcgi_pass 127.0.0.1:9074; - fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME /var/www/html/phpMyAdmin$fastcgi_script_name; - } - } #error_page 404 /404.html; diff --git a/nginx/docker-compose.yml b/nginx/docker-compose.yml index 3624287..ce2735f 100644 --- a/nginx/docker-compose.yml +++ b/nginx/docker-compose.yml @@ -12,6 +12,7 @@ services: - ./conf/vhost:/usr/local/nginx/conf/vhost - ./conf/stream:/usr/local/nginx/conf/stream - ./logs:/usr/local/nginx/logs + - ./ssl:/usr/local/nginx/conf/ssl restart: always \ No newline at end of file diff --git a/nginx/sh/install_nginx.sh b/nginx/sh/install_nginx.sh index 0ff7499..f1b2410 100644 --- a/nginx/sh/install_nginx.sh +++ b/nginx/sh/install_nginx.sh @@ -43,7 +43,9 @@ install_before(){ #创建软连接 ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx #创建缓存文件夹 - mkdir -p /data/caches + # mkdir -p /data/caches + # 创建SSL证书文件夹 + mkdir -p /usr/local/nginx/conf/ssl #创建站点文件夹 mkdir -p /var/www/html } @@ -71,7 +73,9 @@ install_nginx(){ #添加定时任务 add_crontab() { echo "添加定时任务" - # echo "*/3 * * * * /root/pull.sh" >> /etc/crontabs/root + # 检测配置文件和SSL证书变化 + echo "*/3 * * * * /root/xc.sh check_change" >> /etc/crontabs/root + # 日志分割 echo "50 23 * * * /usr/sbin/logrotate -f /etc/logrotate.d/nginx" >> /etc/crontabs/root } diff --git a/nginx/sh/xc.sh b/nginx/sh/xc.sh index 65ef321..d163673 100644 --- a/nginx/sh/xc.sh +++ b/nginx/sh/xc.sh @@ -9,6 +9,11 @@ NGINX_PATH="/usr/local/nginx" nginx="${NGINX_PATH}/sbin/nginx" +# 配置文件路径 +CONF_PATH="${NGINX_PATH}/conf/" +# SSL证书路径 +SSL_PATH="${CONF_PATH}/ssl/" + #获取用户传递的参数 arg1=$1 @@ -45,6 +50,14 @@ function check_conf() { $nginx -t } +# 检查配置/SSL证书是否有更新,有更新则重载 +function check_change() { + find ${CONF_PATH}/conf/ -mmin -1 -exec /usr/sbin/xc.sh reload {} + + echo '-------------------------------------' + sleep 3 + find ${SSL_PATH}/ssl/ -mmin -1 -exec /usr/sbin/xc.sh reload {} + +} + # 根据用户输入执行不同动作 case ${arg1} in @@ -63,6 +76,9 @@ case ${arg1} in '-t') check_conf ;; + 'check_change') + check_change + ;; *) echo 'Parameter error!' ;; diff --git a/php/Dockerfile b/php/Dockerfile deleted file mode 100644 index d0b7cbe..0000000 --- a/php/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM php:7.3-fpm-alpine3.12 -#设置时区,仅Debian需要 -#ENV TZ=Asia/Shanghai -#工作目录 -WORKDIR /root -#复制安装脚本 -COPY ./install.sh /root -#复制启动脚本 -COPY ./run.sh /usr/sbin -#执行安装脚本 -RUN sh install.sh -#暴露配置文件 -VOLUME /etc/nginx/conf.d -VOLUME /var/www/html -VOLUME /var/log/nginx -EXPOSE 80 -EXPOSE 443 -#运行crontab和nginx -CMD ["/usr/sbin/run.sh"] \ No newline at end of file diff --git a/php/install.sh b/php/install.sh deleted file mode 100644 index 20a96b5..0000000 --- a/php/install.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -#更新软件 -apk update -#安装timezone -apk add -U tzdata -#查看时区列表 -ls /usr/share/zoneinfo -#拷贝需要的时区文件到localtime -cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime -#查看当前时间 -date -#为了精简镜像,可以将tzdata删除了 -apk del tzdata -#安装wget -apk add wget -chmod +x /usr/sbin/run.sh - - -#安装nginx -function install_nginx() { - #安装nginx - apk add nginx - mkdir -p /run/nginx/ - #wget -P /etc/nginx https://github.com/helloxz/dnmp/raw/main/php/nginx.conf -} -#设置PHP -function set_php(){ - #安装依赖 - apk add --no-cache autoconf gcc musl-dev g++ zlib-dev make libpng libpng-dev libjpeg-turbo-dev libwebp-dev zlib-dev libxpm-dev - #安装GD库 依赖 - #apk add libpng-dev - #设置php.ini - cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini - #zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so - #sed -i "s/www-data/www/g" /usr/local/etc/php-fpm.d/www.conf - #安装扩展 - docker-php-ext-install gd - pecl install redis-5.1.1 \ - && pecl install xdebug-2.8.1 \ - && docker-php-ext-enable redis xdebug -} - -#清理工作 -function run_clean(){ - apk del autoconf gcc musl-dev g++ zlib-dev make libpng libpng-dev libjpeg-turbo-dev libwebp-dev zlib-dev libxpm-dev - #清理编译 - rm -rf /var/cache/apk/* -} -install_nginx && set_php && run_clean - -echo '-----------------------------' -echo 'nginx + php install success.' -echo '-----------------------------' \ No newline at end of file diff --git a/php/nginx.conf b/php/nginx.conf deleted file mode 100644 index 6ec146b..0000000 --- a/php/nginx.conf +++ /dev/null @@ -1,158 +0,0 @@ -user www-data www-data; -worker_processes auto; -worker_rlimit_nofile 50000; -error_log logs/error.log; -#error_log logs/error.log notice; -#error_log logs/error.log info; - -pid /var/run/nginx.pid; - - -events { - use epoll; - worker_connections 51200; - #worker_connections 1024; - multi_accept on; -} - - -http { - include mime.types; - default_type application/octet-stream; - server_names_hash_bucket_size 128; - client_header_buffer_size 32k; - large_client_header_buffers 4 32k; - client_max_body_size 1024m; - client_body_buffer_size 10m; - sendfile on; - tcp_nopush on; - keepalive_timeout 120; - server_tokens off; - tcp_nodelay on; - proxy_headers_hash_max_size 51200; - proxy_headers_hash_bucket_size 6400; - #开启Brotli压缩 - brotli on; - brotli_comp_level 6; - #最小长度 - brotli_min_length 512; - brotli_types text/plain text/javascript text/css text/xml text/x-component application/javascript application/x-javascript application/xml application/json application/xhtml+xml application/rss+xml application/atom+xml application/x-font-ttf application/vnd.ms-fontobject image/svg+xml image/x-icon font/opentype; - brotli_static always; - - gzip on; - gzip_buffers 16 8k; - gzip_comp_level 6; - gzip_http_version 1.1; - gzip_min_length 256; - gzip_proxied any; - gzip_vary on; - gzip_types - text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml - text/javascript application/javascript application/x-javascript - text/x-json application/json application/x-web-app-manifest+json - text/css text/plain text/x-component - font/opentype application/x-font-ttf application/vnd.ms-fontobject - image/x-icon; - gzip_disable "MSIE [1-6]\.(?!.*SV1)"; - - #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency. - open_file_cache max=1000 inactive=20s; - open_file_cache_valid 30s; - open_file_cache_min_uses 2; - open_file_cache_errors on; - - #limit connection - limit_conn_zone $binary_remote_addr zone=addr:10m; - - - server { - listen 80; - server_name localhost; - root /var/www/html; - index index.html index.htm index.php; - - #charset koi8-r; - - #access_log logs/host.access.log main; - - #location / { - # root /var/www/html; - # index index.html index.htm index.php; - #} - location ~ [^/]\.php(/|$) { - fastcgi_pass 127.0.0.1:9000; - fastcgi_index index.php; - include fastcgi.conf; - } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root html; - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} - } - - - # another virtual host using mix of IP-, name-, and port-based configuration - # - #server { - # listen 8000; - # listen somename:8080; - # server_name somename alias another.alias; - - # location / { - # root html; - # index index.html index.htm; - # } - #} - - - # HTTPS server - # - #server { - # listen 443 ssl; - # server_name localhost; - - # ssl_certificate cert.pem; - # ssl_certificate_key cert.key; - - # ssl_session_cache shared:SSL:1m; - # ssl_session_timeout 5m; - - # ssl_ciphers HIGH:!aNULL:!MD5; - # ssl_prefer_server_ciphers on; - - # location / { - # root html; - # index index.html index.htm; - # } - #} - include cdn/*.conf; - include vhost/*.conf; -} \ No newline at end of file diff --git a/php/run.sh b/php/run.sh deleted file mode 100644 index 50445c7..0000000 --- a/php/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -#start nginx -/usr/sbin/nginx -echo 'start nginx success.' -#start php-fpm -/usr/local/sbin/php-fpm \ No newline at end of file diff --git a/php74/docker-compose.yaml b/php74/docker-compose.yaml index 58cfcad..fbc70c0 100644 --- a/php74/docker-compose.yaml +++ b/php74/docker-compose.yaml @@ -5,6 +5,8 @@ services: image: helloz/php:7.4-fpm-alpine network_mode: host container_name: php-7.4 + # Specify User ID and User Group + # user: "1000:1000" volumes: - ./www.conf:/usr/local/etc/php-fpm.d/www.conf - ./php.ini:/usr/local/etc/php/conf.d/php.ini diff --git a/php74/www.conf b/php74/www.conf index f287b2b..02d5fe5 100644 --- a/php74/www.conf +++ b/php74/www.conf @@ -434,6 +434,6 @@ catch_workers_output = yes ; specified at startup with the -d argument ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com ;php_flag[display_errors] = off -;php_admin_value[error_log] = /var/log/fpm-php.www.log -;php_admin_flag[log_errors] = on +php_admin_value[error_log] = log/fpm-php.www.log +php_admin_flag[log_errors] = on ;php_admin_value[memory_limit] = 32M diff --git a/wwwroot/default/index.html b/wwwroot/default/index.html new file mode 100644 index 0000000..5e5fed9 --- /dev/null +++ b/wwwroot/default/index.html @@ -0,0 +1,49 @@ + + + + + + Welcome to DNMP + + + + + +
+
+

Welcome to DNMP!

+

DNMP is a powerful stack for web development, combining Docker, Nginx, MySQL, and PHP.

+
+

Learn more about how DNMP can streamline your development process and make your projects more efficient.

+ +
+
+ + + + diff --git a/wwwroot/phpMyAdmin.zip b/wwwroot/phpMyAdmin.zip deleted file mode 100644 index 2a1e7b8..0000000 Binary files a/wwwroot/phpMyAdmin.zip and /dev/null differ