├── .env ├── .env.dev ├── .gitignore ├── Octane.md ├── README.md ├── app └── .gitkeep ├── config ├── nginx │ ├── cert │ │ └── .gitkeep │ ├── default.conf │ ├── laravel.conf │ └── thinkphp.conf ├── php │ ├── docker-upload.ini │ └── www.conf └── redis │ └── redis.conf ├── database ├── mysql │ └── .gitkeep └── redis │ └── .gitkeep ├── docker-compose-dev.yml ├── docker-compose.yml └── storage └── logs └── redis └── redis.log /.env: -------------------------------------------------------------------------------- 1 | ENV=local 2 | 3 | TIMEZONE=Asia/Shanghai 4 | 5 | # [image] 6 | NGINX=nginx:1.27.2-alpine 7 | MYSQL=mysql:8.4.3 8 | REDIS=redis:7.4.1-alpine 9 | PHP=xgbnl/php:8.3.13-fpm 10 | 11 | # [mysql] 12 | MYSQL_ROOT_PASSWORD=password 13 | MYSQL_DATABASE=laravel 14 | MYSQL_USER=laravel 15 | MYSQL_PASSWORD=password 16 | CHARACTER_SET_SERVER=utf8mb4 17 | COLLATION_SERVER=utf8mb4_general_ci 18 | EXPLICIT_DEFAULTS_FOR_TIMESTAMP=off 19 | DEFAULT_STORAGE_ENGINE=INNODB 20 | SQL_MODE='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' 21 | LOWER_CASE_TABLE_NAMES=1 22 | 23 | # [path] 24 | APP=./app 25 | CONTAINER=/var/www/html 26 | 27 | #[config] 28 | CONFIG=./config 29 | 30 | #[database] 31 | DATABASE=./database 32 | 33 | #[storage] 34 | STORAGE=./storage 35 | 36 | #[permission] 37 | UID=1000 38 | GID=1000 39 | -------------------------------------------------------------------------------- /.env.dev: -------------------------------------------------------------------------------- 1 | ENV=local 2 | 3 | TIMEZONE=Asia/Shanghai 4 | 5 | # [image] 6 | NGINX=nginx:1.27.2-alpine 7 | MYSQL=mysql:8.4.3 8 | MYSQL_FIVE=mysql:5.7.44 9 | REDIS=redis:7.4.1-alpine 10 | PHP=xgbnl/php:8.3.13-fpm 11 | PHP_SEVEN=xgbnl/php:7.4.33-fpm 12 | 13 | # [mysql] 14 | MYSQL_ROOT_PASSWORD=password 15 | MYSQL_DATABASE=laravel 16 | MYSQL_USER=laravel 17 | MYSQL_PASSWORD=password 18 | DEFAULT_AUTHENTICATION_PLUGIN=mysql_native_password 19 | CHARACTER_SET_SERVER=utf8mb4 20 | COLLATION_SERVER=utf8mb4_general_ci 21 | EXPLICIT_DEFAULTS_FOR_TIMESTAMP=off 22 | DEFAULT_STORAGE_ENGINE=INNODB 23 | SQL_MODE='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION' 24 | LOWER_CASE_TABLE_NAMES=1 25 | 26 | # [path] 27 | APP=./app 28 | CONTAINER=/var/www/html 29 | 30 | #[config] 31 | CONFIG=./config 32 | 33 | #[database] 34 | DATABASE=./database 35 | 36 | #[storage] 37 | STORAGE=./storage 38 | 39 | #[permission] 40 | UID=1000 41 | GID=1000 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.vscode 3 | -------------------------------------------------------------------------------- /Octane.md: -------------------------------------------------------------------------------- 1 | ## 关于运行Laravel Octane 2 | #### nginx `octane.conf` 3 | ``` 4 | map $http_upgrade $connection_upgrade { 5 | default upgrade; 6 | '' close; 7 | } 8 | 9 | upstream app { 10 | server php:8000; 11 | } 12 | 13 | server { 14 | listen 80; 15 | listen [::]:80; 16 | server_name laravel.test; 17 | server_tokens off; 18 | root /var/www/html/laravel/public; 19 | 20 | index index.php; 21 | 22 | charset utf-8; 23 | 24 | location /index.php { 25 | try_files /not_exists @octane; 26 | } 27 | 28 | location / { 29 | try_files $uri $uri/ @octane; 30 | } 31 | 32 | location = /favicon.ico { access_log off; log_not_found off; } 33 | location = /robots.txt { access_log off; log_not_found off; } 34 | 35 | access_log off; 36 | 37 | error_page 404 /index.php; 38 | 39 | location @octane { 40 | set $suffix ""; 41 | 42 | if ($uri = /index.php) { 43 | set $suffix ?$query_string; 44 | } 45 | 46 | proxy_http_version 1.1; 47 | proxy_set_header Host $http_host; 48 | proxy_set_header Scheme $scheme; 49 | proxy_set_header SERVER_PORT $server_port; 50 | proxy_set_header REMOTE_ADDR $remote_addr; 51 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 52 | proxy_set_header Upgrade $http_upgrade; 53 | proxy_set_header Connection $connection_upgrade; 54 | 55 | proxy_pass http://app$suffix; 56 | } 57 | } 58 | ``` 59 | #### 运行Octane 60 | 61 | 必须指定`host=0.0.0.0`,否则`nginx`容器无法访问 62 | 63 | ```shell 64 | php artisan octane:start --host=0.0.0.0 --port=8000 65 | ``` 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Laradock 3 | 4 | > Laravel 开发环境 5 | 6 | #### 目录结构 7 | ``` 8 | ├── README.md 9 | ├── app 10 | ├── config 11 | │   ├── nginx 12 | │   │   ├── cert 13 | │   │   ├── default.conf 14 | │   │   └── laravel.conf 15 | │   ├── php 16 | │   │   ├── docker-upload.ini 17 | │   │   └── www.conf 18 | │   └── redis 19 | │   └── redis.conf 20 | ├── database 21 | │   ├── mysql 22 | │   └── redis 23 | ├── docker-compose.yml 24 | └── storage 25 | └── logs 26 | └── redis 27 | └── redis.log 28 | ``` 29 | 30 | #### 构建容器 31 | 32 | ```shell 33 | $ git clone https://github.com/xgbnl/laradock.git 34 | 35 | $ cd laradock 36 | 37 | $ sudo docker-compose up -d --build 38 | ``` 39 | 40 | #### 更新容器 41 | ```shell 42 | $ sudo docker-compose up -d --build php 43 | ``` 44 | 45 | #### 项目配置SQL与Redis 46 | 47 | ```dotenv 48 | # MYSQL 49 | DB_CONNECTION=mysql 50 | DB_HOST=mysql #指定Mysql容器名称 51 | DB_PORT=3306 52 | DB_DATABASE=laravel 53 | DB_USERNAME=laravel 54 | DB_PASSWORD=password 55 | 56 | # Redis 57 | REDIS_HOST=redis #指定Redis容器名称 58 | REDIS_USERNAME=default 59 | REDIS_PASSWORD=123456 60 | REDIS_PORT=6379 61 | ``` 62 | 63 | #### 单机式布署 64 | > 该布署方式适用于 `Laravel` 项目与前端项目使用同一域名时 65 | 66 | ```editorconfig 67 | 68 | server { 69 | ... 70 | 71 | ... 72 | 73 | # 解析你的Laravel项目,让react项目能够正常访问 74 | location /api { 75 | try_files $uri $uri/ /index.php?$query_string; 76 | } 77 | 78 | # 解析你的 React app 79 | location /react/app { 80 | alias /var/www/html/react-app/dist/; 81 | index index.html; 82 | try_file $uri $uri/ /react/app/index.html; 83 | } 84 | 85 | # 当部署为 Vue 项目 时 86 | location /vue/app/ { 87 | alias /var/www/html/web/dist/; 88 | } 89 | 90 | # 解析你上传至服务器的文件 91 | # 当访问: https://www.website.com/uploads/images/logo.png 92 | # 文件时,nginx会自动解析 uploads 开头的目录 93 | location ^~ /uploads/ { 94 | alias /var/www/html/laravel/storage/uploads/images/; 95 | } 96 | 97 | } 98 | 99 | ``` 100 | 101 | #### 配置SSH证书 102 | 在阿里云或其它服务器厂商购买到的SSL证书请存放至 `cert` 目录 103 | ```shell 104 | config/nginx/cert 105 | ``` 106 | 最后替换`laravel.conf`配置文件中的`ssl`文件名 107 | 108 | #### Thinkphp 109 | 新增Thinkphp和Fastadmin老项目支持,如使用将`docker-compose-dev.yml`替换为`docker-compose.yml`文件、`.env.dev`替换为`.env`即可. 110 | -------------------------------------------------------------------------------- /app/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgbnl/laradock/1c33926a670d7af870564dd6907c90f8ff7c1430/app/.gitkeep -------------------------------------------------------------------------------- /config/nginx/cert/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgbnl/laradock/1c33926a670d7af870564dd6907c90f8ff7c1430/config/nginx/cert/.gitkeep -------------------------------------------------------------------------------- /config/nginx/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | listen [::]:80; 4 | server_name localhost; 5 | 6 | #access_log /var/log/nginx/host.access.log main; 7 | 8 | location / { 9 | root /usr/share/nginx/html; 10 | index index.html index.htm; 11 | } 12 | 13 | #error_page 404 /404.html; 14 | 15 | # redirect server error pages to the static page /50x.html 16 | # 17 | error_page 500 502 503 504 /50x.html; 18 | location = /50x.html { 19 | root /usr/share/nginx/html; 20 | } 21 | 22 | # proxy the PHP scripts to Apache listening on 127.0.0.1:80 23 | # 24 | #location ~ \.php$ { 25 | # proxy_pass http://127.0.0.1; 26 | #} 27 | 28 | # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 29 | # 30 | #location ~ \.php$ { 31 | # root html; 32 | # fastcgi_pass 127.0.0.1:9000; 33 | # fastcgi_index index.php; 34 | # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 35 | # include fastcgi_params; 36 | #} 37 | 38 | # deny access to .htaccess files, if Apache's document root 39 | # concurs with nginx's one 40 | # 41 | #location ~ /\.ht { 42 | # deny all; 43 | #} 44 | } 45 | 46 | -------------------------------------------------------------------------------- /config/nginx/laravel.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | #listen 443 ssl; #云服务器请开始443端口 4 | #替换 5 | server_name www.your_website.com; 6 | root /var/www/html/laravel/public; 7 | 8 | #配置SSL证书,替换 9 | #ssl_certificate conf.d/cert/your_cert_file.pem; 10 | #ssl_certificate_key conf.d/cert/your_cert_file.key; 11 | #ssl_session_timeout 5m; 12 | #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 13 | 14 | #表示使用的加密套件的类型。 15 | #表示使用的TLS协议的类型,您需要自行评估是否配置TLSv1.1协议。 16 | #ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; 17 | #ssl_prefer_server_ciphers on; 18 | 19 | add_header X-Frame-Options "SAMEORIGIN"; 20 | add_header X-XSS-Protection "1; mode=block"; 21 | add_header X-Content-Type-Options "nosniff"; 22 | 23 | # 分片上传大小限制 24 | client_max_body_size 100m; 25 | 26 | index index.html index.htm index.php; 27 | 28 | charset utf-8; 29 | 30 | location / { 31 | try_files $uri $uri/ /index.php?$query_string; 32 | } 33 | 34 | location = /favicon.ico { access_log off; log_not_found off; } 35 | location = /robots.txt { access_log off; log_not_found off; } 36 | 37 | error_page 404 /index.php; 38 | 39 | location ~ \.php$ { 40 | fastcgi_split_path_info ^(.+\.php)(/.+)$; 41 | fastcgi_pass php:9000; 42 | fastcgi_index index.php; 43 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 44 | include fastcgi_params; 45 | } 46 | 47 | location ~ /\.(?!well-known).* { 48 | deny all; 49 | } 50 | } -------------------------------------------------------------------------------- /config/nginx/thinkphp.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | #listen 443 ssl; #云服务器请开始443端口 4 | #替换 5 | server_name thinkphp.test; 6 | root /var/www/html/thinkphp/public; 7 | 8 | #配置SSL证书,替换 9 | #ssl_certificate conf.d/cert/your_cert_file.pem; 10 | #ssl_certificate_key conf.d/cert/your_cert_file.key; 11 | #ssl_session_timeout 5m; 12 | #ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; 13 | 14 | #表示使用的加密套件的类型。 15 | #表示使用的TLS协议的类型,您需要自行评估是否配置TLSv1.1协议。 16 | #ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; 17 | #ssl_prefer_server_ciphers on; 18 | 19 | add_header X-Frame-Options "SAMEORIGIN"; 20 | add_header X-XSS-Protection "1; mode=block"; 21 | add_header X-Content-Type-Options "nosniff"; 22 | 23 | # 分片上传大小限制 24 | client_max_body_size 100m; 25 | 26 | index index.html index.htm index.php; 27 | 28 | charset utf-8; 29 | 30 | location / { 31 | if (!-e $request_filename){ 32 | rewrite ^(.*)$ /index.php?s=$1 last; break; 33 | } 34 | } 35 | 36 | location = /favicon.ico { access_log off; log_not_found off; } 37 | location = /robots.txt { access_log off; log_not_found off; } 38 | 39 | error_page 404 /index.php; 40 | 41 | #location ~ ^(.+\.php)(.*)$ { 42 | #fastcgi_pass php_seven:9000; 43 | #fastcgi_split_path_info ^(.+\.php)(.*)$; 44 | #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 45 | #fastcgi_param PATH_INFO $fastcgi_path_info; 46 | #include fastcgi_params; 47 | # } 48 | 49 | location ~ [^/]\.php(/|$) { 50 | try_files $uri =404; 51 | fastcgi_pass php_seven:9000; 52 | fastcgi_index index.php; 53 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 54 | fastcgi_param QUERY_STRING $query_string; 55 | fastcgi_param REQUEST_METHOD $request_method; 56 | fastcgi_param CONTENT_TYPE $content_type; 57 | fastcgi_param CONTENT_LENGTH $content_length; 58 | 59 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 60 | fastcgi_param REQUEST_URI $request_uri; 61 | fastcgi_param DOCUMENT_URI $document_uri; 62 | fastcgi_param DOCUMENT_ROOT $document_root; 63 | fastcgi_param SERVER_PROTOCOL $server_protocol; 64 | fastcgi_param REQUEST_SCHEME $scheme; 65 | fastcgi_param HTTPS $https if_not_empty; 66 | 67 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 68 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 69 | 70 | fastcgi_param REMOTE_ADDR $remote_addr; 71 | fastcgi_param REMOTE_PORT $remote_port; 72 | fastcgi_param SERVER_ADDR $server_addr; 73 | fastcgi_param SERVER_PORT $server_port; 74 | fastcgi_param SERVER_NAME $server_name; 75 | 76 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 77 | fastcgi_param REDIRECT_STATUS 200; 78 | 79 | set $real_script_name $fastcgi_script_name; 80 | if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { 81 | set $real_script_name $1; 82 | set $path_info $2; 83 | } 84 | 85 | fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; 86 | fastcgi_param SCRIPT_NAME $real_script_name; 87 | fastcgi_param PATH_INFO $path_info; 88 | 89 | } 90 | 91 | location ~ /\.(?!well-known).* { 92 | deny all; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /config/php/docker-upload.ini: -------------------------------------------------------------------------------- 1 | ; https://github.com/docker-library/php/issues/878#issuecomment-938595965 2 | 3 | ; Maximum size of POST data that PHP will accept. 4 | post_max_size = 105M 5 | 6 | ; Maximum allowed size for uploaded files. 7 | upload_max_filesize = 100M 8 | -------------------------------------------------------------------------------- /config/php/www.conf: -------------------------------------------------------------------------------- 1 | ; Start a new pool named 'www'. 2 | ; the variable $pool can be used in any directive and will be replaced by the 3 | ; pool name ('www' here) 4 | [www] 5 | 6 | ; Per pool prefix 7 | ; It only applies on the following directives: 8 | ; - 'access.log' 9 | ; - 'slowlog' 10 | ; - 'listen' (unixsocket) 11 | ; - 'chroot' 12 | ; - 'chdir' 13 | ; - 'php_values' 14 | ; - 'php_admin_values' 15 | ; When not set, the global prefix (or NONE) applies instead. 16 | ; Note: This directive can also be relative to the global prefix. 17 | ; Default Value: none 18 | ;prefix = /path/to/pools/$pool 19 | 20 | ; Unix user/group of the child processes. This can be used only if the master 21 | ; process running user is root. It is set after the child process is created. 22 | ; The user and group can be specified either by their name or by their numeric 23 | ; IDs. 24 | ; Note: If the user is root, the executable needs to be started with 25 | ; --allow-to-run-as-root option to work. 26 | ; Default Values: The user is set to master process running user by default. 27 | ; If the group is not set, the user's group is used. 28 | ;user = www-data 29 | ;group = www-data 30 | 31 | ; The address on which to accept FastCGI requests. 32 | ; Valid syntaxes are: 33 | ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on 34 | ; a specific port; 35 | ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on 36 | ; a specific port; 37 | ; 'port' - to listen on a TCP socket to all addresses 38 | ; (IPv6 and IPv4-mapped) on a specific port; 39 | ; '/path/to/unix/socket' - to listen on a unix socket. 40 | ; Note: This value is mandatory. 41 | listen = 127.0.0.1:9000 42 | 43 | ; Set listen(2) backlog. 44 | ; Default Value: 511 (-1 on Linux, FreeBSD and OpenBSD) 45 | ;listen.backlog = 511 46 | 47 | ; Set permissions for unix socket, if one is used. In Linux, read/write 48 | ; permissions must be set in order to allow connections from a web server. Many 49 | ; BSD-derived systems allow connections regardless of permissions. The owner 50 | ; and group can be specified either by name or by their numeric IDs. 51 | ; Default Values: Owner is set to the master process running user. If the group 52 | ; is not set, the owner's group is used. Mode is set to 0660. 53 | ;listen.owner = www-data 54 | ;listen.group = www-data 55 | ;listen.mode = 0660 56 | 57 | ; When POSIX Access Control Lists are supported you can set them using 58 | ; these options, value is a comma separated list of user/group names. 59 | ; When set, listen.owner and listen.group are ignored 60 | ;listen.acl_users = 61 | ;listen.acl_groups = 62 | 63 | ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect. 64 | ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original 65 | ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address 66 | ; must be separated by a comma. If this value is left blank, connections will be 67 | ; accepted from any ip address. 68 | ; Default Value: any 69 | ;listen.allowed_clients = 127.0.0.1 70 | 71 | ; Set the associated the route table (FIB). FreeBSD only 72 | ; Default Value: -1 73 | ;listen.setfib = 1 74 | 75 | ; Specify the nice(2) priority to apply to the pool processes (only if set) 76 | ; The value can vary from -19 (highest priority) to 20 (lower priority) 77 | ; Note: - It will only work if the FPM master process is launched as root 78 | ; - The pool processes will inherit the master process priority 79 | ; unless it specified otherwise 80 | ; Default Value: no set 81 | ; process.priority = -19 82 | 83 | ; Set the process dumpable flag (PR_SET_DUMPABLE prctl for Linux or 84 | ; PROC_TRACE_CTL procctl for FreeBSD) even if the process user 85 | ; or group is different than the master process user. It allows to create process 86 | ; core dump and ptrace the process for the pool user. 87 | ; Default Value: no 88 | ; process.dumpable = yes 89 | 90 | ; Choose how the process manager will control the number of child processes. 91 | ; Possible Values: 92 | ; static - a fixed number (pm.max_children) of child processes; 93 | ; dynamic - the number of child processes are set dynamically based on the 94 | ; following directives. With this process management, there will be 95 | ; always at least 1 children. 96 | ; pm.max_children - the maximum number of children that can 97 | ; be alive at the same time. 98 | ; pm.start_servers - the number of children created on startup. 99 | ; pm.min_spare_servers - the minimum number of children in 'idle' 100 | ; state (waiting to process). If the number 101 | ; of 'idle' processes is less than this 102 | ; number then some children will be created. 103 | ; pm.max_spare_servers - the maximum number of children in 'idle' 104 | ; state (waiting to process). If the number 105 | ; of 'idle' processes is greater than this 106 | ; number then some children will be killed. 107 | ; pm.max_spawn_rate - the maximum number of rate to spawn child 108 | ; processes at once. 109 | ; ondemand - no children are created at startup. Children will be forked when 110 | ; new requests will connect. The following parameter are used: 111 | ; pm.max_children - the maximum number of children that 112 | ; can be alive at the same time. 113 | ; pm.process_idle_timeout - The number of seconds after which 114 | ; an idle process will be killed. 115 | ; Note: This value is mandatory. 116 | pm = dynamic 117 | 118 | ; The number of child processes to be created when pm is set to 'static' and the 119 | ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. 120 | ; This value sets the limit on the number of simultaneous requests that will be 121 | ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork. 122 | ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP 123 | ; CGI. The below defaults are based on a server without much resources. Don't 124 | ; forget to tweak pm.* to fit your needs. 125 | ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' 126 | ; Note: This value is mandatory. 127 | pm.max_children = 5 128 | 129 | ; The number of child processes created on startup. 130 | ; Note: Used only when pm is set to 'dynamic' 131 | ; Default Value: (min_spare_servers + max_spare_servers) / 2 132 | pm.start_servers = 2 133 | 134 | ; The desired minimum number of idle server processes. 135 | ; Note: Used only when pm is set to 'dynamic' 136 | ; Note: Mandatory when pm is set to 'dynamic' 137 | pm.min_spare_servers = 1 138 | 139 | ; The desired maximum number of idle server processes. 140 | ; Note: Used only when pm is set to 'dynamic' 141 | ; Note: Mandatory when pm is set to 'dynamic' 142 | pm.max_spare_servers = 3 143 | 144 | ; The number of rate to spawn child processes at once. 145 | ; Note: Used only when pm is set to 'dynamic' 146 | ; Note: Mandatory when pm is set to 'dynamic' 147 | ; Default Value: 32 148 | ;pm.max_spawn_rate = 32 149 | 150 | ; The number of seconds after which an idle process will be killed. 151 | ; Note: Used only when pm is set to 'ondemand' 152 | ; Default Value: 10s 153 | ;pm.process_idle_timeout = 10s; 154 | 155 | ; The number of requests each child process should execute before respawning. 156 | ; This can be useful to work around memory leaks in 3rd party libraries. For 157 | ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. 158 | ; Default Value: 0 159 | ;pm.max_requests = 500 160 | 161 | ; The URI to view the FPM status page. If this value is not set, no URI will be 162 | ; recognized as a status page. It shows the following information: 163 | ; pool - the name of the pool; 164 | ; process manager - static, dynamic or ondemand; 165 | ; start time - the date and time FPM has started; 166 | ; start since - number of seconds since FPM has started; 167 | ; accepted conn - the number of request accepted by the pool; 168 | ; listen queue - the number of request in the queue of pending 169 | ; connections (see backlog in listen(2)); 170 | ; max listen queue - the maximum number of requests in the queue 171 | ; of pending connections since FPM has started; 172 | ; listen queue len - the size of the socket queue of pending connections; 173 | ; idle processes - the number of idle processes; 174 | ; active processes - the number of active processes; 175 | ; total processes - the number of idle + active processes; 176 | ; max active processes - the maximum number of active processes since FPM 177 | ; has started; 178 | ; max children reached - number of times, the process limit has been reached, 179 | ; when pm tries to start more children (works only for 180 | ; pm 'dynamic' and 'ondemand'); 181 | ; Value are updated in real time. 182 | ; Example output: 183 | ; pool: www 184 | ; process manager: static 185 | ; start time: 01/Jul/2011:17:53:49 +0200 186 | ; start since: 62636 187 | ; accepted conn: 190460 188 | ; listen queue: 0 189 | ; max listen queue: 1 190 | ; listen queue len: 42 191 | ; idle processes: 4 192 | ; active processes: 11 193 | ; total processes: 15 194 | ; max active processes: 12 195 | ; max children reached: 0 196 | ; 197 | ; By default the status page output is formatted as text/plain. Passing either 198 | ; 'html', 'xml' or 'json' in the query string will return the corresponding 199 | ; output syntax. Example: 200 | ; http://www.foo.bar/status 201 | ; http://www.foo.bar/status?json 202 | ; http://www.foo.bar/status?html 203 | ; http://www.foo.bar/status?xml 204 | ; 205 | ; By default the status page only outputs short status. Passing 'full' in the 206 | ; query string will also return status for each pool process. 207 | ; Example: 208 | ; http://www.foo.bar/status?full 209 | ; http://www.foo.bar/status?json&full 210 | ; http://www.foo.bar/status?html&full 211 | ; http://www.foo.bar/status?xml&full 212 | ; The Full status returns for each process: 213 | ; pid - the PID of the process; 214 | ; state - the state of the process (Idle, Running, ...); 215 | ; start time - the date and time the process has started; 216 | ; start since - the number of seconds since the process has started; 217 | ; requests - the number of requests the process has served; 218 | ; request duration - the duration in µs of the requests; 219 | ; request method - the request method (GET, POST, ...); 220 | ; request URI - the request URI with the query string; 221 | ; content length - the content length of the request (only with POST); 222 | ; user - the user (PHP_AUTH_USER) (or '-' if not set); 223 | ; script - the main script called (or '-' if not set); 224 | ; last request cpu - the %cpu the last request consumed 225 | ; it's always 0 if the process is not in Idle state 226 | ; because CPU calculation is done when the request 227 | ; processing has terminated; 228 | ; last request memory - the max amount of memory the last request consumed 229 | ; it's always 0 if the process is not in Idle state 230 | ; because memory calculation is done when the request 231 | ; processing has terminated; 232 | ; If the process is in Idle state, then informations are related to the 233 | ; last request the process has served. Otherwise informations are related to 234 | ; the current request being served. 235 | ; Example output: 236 | ; ************************ 237 | ; pid: 31330 238 | ; state: Running 239 | ; start time: 01/Jul/2011:17:53:49 +0200 240 | ; start since: 63087 241 | ; requests: 12808 242 | ; request duration: 1250261 243 | ; request method: GET 244 | ; request URI: /test_mem.php?N=10000 245 | ; content length: 0 246 | ; user: - 247 | ; script: /home/fat/web/docs/php/test_mem.php 248 | ; last request cpu: 0.00 249 | ; last request memory: 0 250 | ; 251 | ; Note: There is a real-time FPM status monitoring sample web page available 252 | ; It's available in: /usr/local/share/php/fpm/status.html 253 | ; 254 | ; Note: The value must start with a leading slash (/). The value can be 255 | ; anything, but it may not be a good idea to use the .php extension or it 256 | ; may conflict with a real PHP file. 257 | ; Default Value: not set 258 | ;pm.status_path = /status 259 | 260 | ; The address on which to accept FastCGI status request. This creates a new 261 | ; invisible pool that can handle requests independently. This is useful 262 | ; if the main pool is busy with long running requests because it is still possible 263 | ; to get the status before finishing the long running requests. 264 | ; 265 | ; Valid syntaxes are: 266 | ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on 267 | ; a specific port; 268 | ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on 269 | ; a specific port; 270 | ; 'port' - to listen on a TCP socket to all addresses 271 | ; (IPv6 and IPv4-mapped) on a specific port; 272 | ; '/path/to/unix/socket' - to listen on a unix socket. 273 | ; Default Value: value of the listen option 274 | ;pm.status_listen = 127.0.0.1:9001 275 | 276 | ; The ping URI to call the monitoring page of FPM. If this value is not set, no 277 | ; URI will be recognized as a ping page. This could be used to test from outside 278 | ; that FPM is alive and responding, or to 279 | ; - create a graph of FPM availability (rrd or such); 280 | ; - remove a server from a group if it is not responding (load balancing); 281 | ; - trigger alerts for the operating team (24/7). 282 | ; Note: The value must start with a leading slash (/). The value can be 283 | ; anything, but it may not be a good idea to use the .php extension or it 284 | ; may conflict with a real PHP file. 285 | ; Default Value: not set 286 | ;ping.path = /ping 287 | 288 | ; This directive may be used to customize the response of a ping request. The 289 | ; response is formatted as text/plain with a 200 response code. 290 | ; Default Value: pong 291 | ;ping.response = pong 292 | 293 | ; The access log file 294 | ; Default: not set 295 | ;access.log = log/$pool.access.log 296 | 297 | ; The access log format. 298 | ; The following syntax is allowed 299 | ; %%: the '%' character 300 | ; %C: %CPU used by the request 301 | ; it can accept the following format: 302 | ; - %{user}C for user CPU only 303 | ; - %{system}C for system CPU only 304 | ; - %{total}C for user + system CPU (default) 305 | ; %d: time taken to serve the request 306 | ; it can accept the following format: 307 | ; - %{seconds}d (default) 308 | ; - %{milliseconds}d 309 | ; - %{milli}d 310 | ; - %{microseconds}d 311 | ; - %{micro}d 312 | ; %e: an environment variable (same as $_ENV or $_SERVER) 313 | ; it must be associated with embraces to specify the name of the env 314 | ; variable. Some examples: 315 | ; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e 316 | ; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e 317 | ; %f: script filename 318 | ; %l: content-length of the request (for POST request only) 319 | ; %m: request method 320 | ; %M: peak of memory allocated by PHP 321 | ; it can accept the following format: 322 | ; - %{bytes}M (default) 323 | ; - %{kilobytes}M 324 | ; - %{kilo}M 325 | ; - %{megabytes}M 326 | ; - %{mega}M 327 | ; %n: pool name 328 | ; %o: output header 329 | ; it must be associated with embraces to specify the name of the header: 330 | ; - %{Content-Type}o 331 | ; - %{X-Powered-By}o 332 | ; - %{Transfert-Encoding}o 333 | ; - .... 334 | ; %p: PID of the child that serviced the request 335 | ; %P: PID of the parent of the child that serviced the request 336 | ; %q: the query string 337 | ; %Q: the '?' character if query string exists 338 | ; %r: the request URI (without the query string, see %q and %Q) 339 | ; %R: remote IP address 340 | ; %s: status (response code) 341 | ; %t: server time the request was received 342 | ; it can accept a strftime(3) format: 343 | ; %d/%b/%Y:%H:%M:%S %z (default) 344 | ; The strftime(3) format must be encapsulated in a %{}t tag 345 | ; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t 346 | ; %T: time the log has been written (the request has finished) 347 | ; it can accept a strftime(3) format: 348 | ; %d/%b/%Y:%H:%M:%S %z (default) 349 | ; The strftime(3) format must be encapsulated in a %{}t tag 350 | ; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t 351 | ; %u: remote user 352 | ; 353 | ; Default: "%R - %u %t \"%m %r\" %s" 354 | ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{milli}d %{kilo}M %C%%" 355 | 356 | ; A list of request_uri values which should be filtered from the access log. 357 | ; 358 | ; As a security precuation, this setting will be ignored if: 359 | ; - the request method is not GET or HEAD; or 360 | ; - there is a request body; or 361 | ; - there are query parameters; or 362 | ; - the response code is outwith the successful range of 200 to 299 363 | ; 364 | ; Note: The paths are matched against the output of the access.format tag "%r". 365 | ; On common configurations, this may look more like SCRIPT_NAME than the 366 | ; expected pre-rewrite URI. 367 | ; 368 | ; Default Value: not set 369 | ;access.suppress_path[] = /ping 370 | ;access.suppress_path[] = /health_check.php 371 | 372 | ; The log file for slow requests 373 | ; Default Value: not set 374 | ; Note: slowlog is mandatory if request_slowlog_timeout is set 375 | ;slowlog = log/$pool.log.slow 376 | 377 | ; The timeout for serving a single request after which a PHP backtrace will be 378 | ; dumped to the 'slowlog' file. A value of '0s' means 'off'. 379 | ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) 380 | ; Default Value: 0 381 | ;request_slowlog_timeout = 0 382 | 383 | ; Depth of slow log stack trace. 384 | ; Default Value: 20 385 | ;request_slowlog_trace_depth = 20 386 | 387 | ; The timeout for serving a single request after which the worker process will 388 | ; be killed. This option should be used when the 'max_execution_time' ini option 389 | ; does not stop script execution for some reason. A value of '0' means 'off'. 390 | ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) 391 | ; Default Value: 0 392 | ;request_terminate_timeout = 0 393 | 394 | ; The timeout set by 'request_terminate_timeout' ini option is not engaged after 395 | ; application calls 'fastcgi_finish_request' or when application has finished and 396 | ; shutdown functions are being called (registered via register_shutdown_function). 397 | ; This option will enable timeout limit to be applied unconditionally 398 | ; even in such cases. 399 | ; Default Value: no 400 | ;request_terminate_timeout_track_finished = no 401 | 402 | ; Set open file descriptor rlimit. 403 | ; Default Value: system defined value 404 | ;rlimit_files = 1024 405 | 406 | ; Set max core size rlimit. 407 | ; Possible Values: 'unlimited' or an integer greater or equal to 0 408 | ; Default Value: system defined value 409 | ;rlimit_core = 0 410 | 411 | ; Chroot to this directory at the start. This value must be defined as an 412 | ; absolute path. When this value is not set, chroot is not used. 413 | ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one 414 | ; of its subdirectories. If the pool prefix is not set, the global prefix 415 | ; will be used instead. 416 | ; Note: chrooting is a great security feature and should be used whenever 417 | ; possible. However, all PHP paths will be relative to the chroot 418 | ; (error_log, sessions.save_path, ...). 419 | ; Default Value: not set 420 | ;chroot = 421 | 422 | ; Chdir to this directory at the start. 423 | ; Note: relative path can be used. 424 | ; Default Value: current directory or / when chroot 425 | ;chdir = /var/www 426 | 427 | ; Redirect worker stdout and stderr into main error log. If not set, stdout and 428 | ; stderr will be redirected to /dev/null according to FastCGI specs. 429 | ; Note: on highloaded environment, this can cause some delay in the page 430 | ; process time (several ms). 431 | ; Default Value: no 432 | ;catch_workers_output = yes 433 | 434 | ; Decorate worker output with prefix and suffix containing information about 435 | ; the child that writes to the log and if stdout or stderr is used as well as 436 | ; log level and time. This options is used only if catch_workers_output is yes. 437 | ; Settings to "no" will output data as written to the stdout or stderr. 438 | ; Default value: yes 439 | ;decorate_workers_output = no 440 | 441 | ; Clear environment in FPM workers 442 | ; Prevents arbitrary environment variables from reaching FPM worker processes 443 | ; by clearing the environment in workers before env vars specified in this 444 | ; pool configuration are added. 445 | ; Setting to "no" will make all environment variables available to PHP code 446 | ; via getenv(), $_ENV and $_SERVER. 447 | ; Default Value: yes 448 | ;clear_env = no 449 | 450 | ; Limits the extensions of the main script FPM will allow to parse. This can 451 | ; prevent configuration mistakes on the web server side. You should only limit 452 | ; FPM to .php extensions to prevent malicious users to use other extensions to 453 | ; execute php code. 454 | ; Note: set an empty value to allow all extensions. 455 | ; Default Value: .php 456 | ;security.limit_extensions = .php .php3 .php4 .php5 .php7 457 | 458 | ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from 459 | ; the current environment. 460 | ; Default Value: clean env 461 | ;env[HOSTNAME] = $HOSTNAME 462 | ;env[PATH] = /usr/local/bin:/usr/bin:/bin 463 | ;env[TMP] = /tmp 464 | ;env[TMPDIR] = /tmp 465 | ;env[TEMP] = /tmp 466 | 467 | ; Additional php.ini defines, specific to this pool of workers. These settings 468 | ; overwrite the values previously defined in the php.ini. The directives are the 469 | ; same as the PHP SAPI: 470 | ; php_value/php_flag - you can set classic ini defines which can 471 | ; be overwritten from PHP call 'ini_set'. 472 | ; php_admin_value/php_admin_flag - these directives won't be overwritten by 473 | ; PHP call 'ini_set' 474 | ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no. 475 | 476 | ; Defining 'extension' will load the corresponding shared extension from 477 | ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not 478 | ; overwrite previously defined php.ini values, but will append the new value 479 | ; instead. 480 | 481 | ; Note: path INI options can be relative and will be expanded with the prefix 482 | ; (pool, global or /usr/local) 483 | 484 | ; Default Value: nothing is defined by default except the values in php.ini and 485 | ; specified at startup with the -d argument 486 | ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com 487 | ;php_flag[display_errors] = off 488 | ;php_admin_value[error_log] = /var/log/fpm-php.www.log 489 | ;php_admin_flag[log_errors] = on 490 | ;php_admin_value[memory_limit] = 32M 491 | -------------------------------------------------------------------------------- /config/redis/redis.conf: -------------------------------------------------------------------------------- 1 | # Redis进程守护,启用守护进程后,Redis会把pid写到一个pidfile中,在/var/run/redis.pid 2 | daemonize no 3 | 4 | # 当Redis以守护进程方式运行时,Redis默认会把pid写入/var/run/redis.pid文件,可以通过pidfile指定 5 | pidfile /var/run/redis.pid 6 | 7 | # 指定Redis监听端口,默认端口为6379 8 | port 6379 9 | 10 | # 绑定的主机地址 11 | # bind 127.0.0.1 12 | bind 0.0.0.0 13 | 14 | # 当客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能 15 | timeout 0 16 | 17 | # 指定日志记录级别,Redis总共支持四个级别:debug、verbose、notice、warning,默认为verbose 18 | # debug (很多信息, 对开发/测试比较有用) 19 | # verbose (many rarely useful info, but not a mess like the debug level) 20 | # notice (moderately verbose, what you want in production probably) 21 | # warning (only very important / critical messages are logged) 22 | loglevel verbose 23 | 24 | # 日志记录方式,默认为标准输出,如果配置为redis为守护进程方式运行,而这里又配置为标准输出,则日志将会发送给/dev/null 25 | logfile /var/log/redis.log 26 | 27 | # 设置数据库的数量,默认数据库为0,可以使用select 命令在连接上指定数据库id 28 | # dbid是从0到‘databases’-1的数目 29 | databases 16 30 | 31 | ################################ SNAPSHOTTING ################################# 32 | # 指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合 33 | # Save the DB on disk: 34 | # 35 | # save 36 | # 37 | # Will save the DB if both the given number of seconds and the given 38 | # number of write operations against the DB occurred. 39 | # 40 | # 满足以下条件将会同步数据: 41 | # 900秒(15分钟)内有1个更改 42 | # 300秒(5分钟)内有10个更改 43 | # 60秒内有10000个更改 44 | # Note: 可以把所有“save”行注释掉,这样就取消同步操作了 45 | 46 | save 900 1 47 | save 300 10 48 | save 60 10000 49 | 50 | # 指定存储至本地数据库时是否压缩数据,默认为yes,Redis采用LZF压缩,如果为了节省CPU时间,可以关闭该选项,但会导致数据库文件变的巨大 51 | rdbcompression yes 52 | 53 | # 指定本地数据库文件名,默认值为dump.rdb 54 | dbfilename dump.rdb 55 | 56 | # 工作目录. 57 | # 指定本地数据库存放目录,文件名由上一个dbfilename配置项指定 58 | # 59 | # Also the Append Only File will be created inside this directory. 60 | # 61 | # 注意,这里只能指定一个目录,不能指定文件名 62 | dir /data 63 | 64 | ################################# REPLICATION ################################# 65 | 66 | # 主从复制。使用slaveof从 Redis服务器复制一个Redis实例。注意,该配置仅限于当前slave有效 67 | # so for example it is possible to configure the slave to save the DB with a 68 | # different interval, or to listen to another port, and so on. 69 | # 设置当本机为slav服务时,设置master服务的ip地址及端口,在Redis启动时,它会自动从master进行数据同步 70 | # slaveof 71 | 72 | 73 | # 当master服务设置了密码保护时,slav服务连接master的密码 74 | # 下文的“requirepass”配置项可以指定密码 75 | # masterauth 76 | 77 | # When a slave lost the connection with the master, or when the replication 78 | # is still in progress, the slave can act in two different ways: 79 | # 80 | # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will 81 | # still reply to client requests, possibly with out of data data, or the 82 | # data set may just be empty if this is the first synchronization. 83 | # 84 | # 2) if slave-serve-stale data is set to 'no' the slave will reply with 85 | # an error "SYNC with master in progress" to all the kind of commands 86 | # but to INFO and SLAVEOF. 87 | # 88 | slave-serve-stale-data yes 89 | 90 | # Slaves send PINGs to server in a predefined interval. It's possible to change 91 | # this interval with the repl_ping_slave_period option. The default value is 10 92 | # seconds. 93 | # 94 | # repl-ping-slave-period 10 95 | 96 | # The following option sets a timeout for both Bulk transfer I/O timeout and 97 | # master data or ping response timeout. The default value is 60 seconds. 98 | # 99 | # It is important to make sure that this value is greater than the value 100 | # specified for repl-ping-slave-period otherwise a timeout will be detected 101 | # every time there is low traffic between the master and the slave. 102 | # 103 | # repl-timeout 60 104 | 105 | ################################## SECURITY ################################### 106 | 107 | # Warning: since Redis is pretty fast an outside user can try up to 108 | # 150k passwords per second against a good box. This means that you should 109 | # use a very strong password otherwise it will be very easy to break. 110 | # 设置Redis连接密码,如果配置了连接密码,客户端在连接Redis时需要通过auth 命令提供密码,默认关闭 111 | requirepass 123456 112 | # Command renaming. 113 | # 114 | # It is possilbe to change the name of dangerous commands in a shared 115 | # environment. For instance the CONFIG command may be renamed into something 116 | # of hard to guess so that it will be still available for internal-use 117 | # tools but not available for general clients. 118 | # 119 | # Example: 120 | # 121 | # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 122 | # 123 | # It is also possilbe to completely kill a command renaming it into 124 | # an empty string: 125 | # 126 | # rename-command CONFIG "" 127 | 128 | ################################### LIMITS #################################### 129 | 130 | # 设置同一时间最大客户端连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件描述符数, 131 | # 如果设置maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max Number of clients reached错误信息 132 | # maxclients 128 133 | 134 | # Don't use more memory than the specified amount of bytes. 135 | # When the memory limit is reached Redis will try to remove keys with an 136 | # EXPIRE set. It will try to start freeing keys that are going to expire 137 | # in little time and preserve keys with a longer time to live. 138 | # Redis will also try to remove objects from free lists if possible. 139 | # 140 | # If all this fails, Redis will start to reply with errors to commands 141 | # that will use more memory, like SET, LPUSH, and so on, and will continue 142 | # to reply to most read-only commands like GET. 143 | # 144 | # WARNING: maxmemory can be a good idea mainly if you want to use Redis as a 145 | # 'state' server or cache, not as a real DB. When Redis is used as a real 146 | # database the memory usage will grow over the weeks, it will be obvious if 147 | # it is going to use too much memory in the long run, and you'll have the time 148 | # to upgrade. With maxmemory after the limit is reached you'll start to get 149 | # errors for write operations, and this may even lead to DB inconsistency. 150 | # 指定Redis最大内存限制,Redis在启动时会把数据加载到内存中,达到最大内存后,Redis会先尝试清除已到期或即将到期的Key, 151 | # 当此方法处理后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。 152 | # Redis新的vm机制,会把Key存放内存,Value会存放在swap区 153 | # maxmemory 154 | 155 | # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory 156 | # is reached? You can select among five behavior: 157 | # 158 | # volatile-lru -> remove the key with an expire set using an LRU algorithm 159 | # allkeys-lru -> remove any key accordingly to the LRU algorithm 160 | # volatile-random -> remove a random key with an expire set 161 | # allkeys->random -> remove a random key, any key 162 | # volatile-ttl -> remove the key with the nearest expire time (minor TTL) 163 | # noeviction -> don't expire at all, just return an error on write operations 164 | # 165 | # Note: with all the kind of policies, Redis will return an error on write 166 | # operations, when there are not suitable keys for eviction. 167 | # 168 | # At the date of writing this commands are: set setnx setex append 169 | # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd 170 | # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby 171 | # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby 172 | # getset mset msetnx exec sort 173 | # 174 | # The default is: 175 | # 176 | # maxmemory-policy volatile-lru 177 | 178 | # LRU and minimal TTL algorithms are not precise algorithms but approximated 179 | # algorithms (in order to save memory), so you can select as well the sample 180 | # size to check. For instance for default Redis will check three keys and 181 | # pick the one that was used less recently, you can change the sample size 182 | # using the following configuration directive. 183 | # 184 | # maxmemory-samples 3 185 | 186 | ############################## APPEND ONLY MODE ############################### 187 | 188 | # 189 | # Note that you can have both the async dumps and the append only file if you 190 | # like (you have to comment the "save" statements above to disable the dumps). 191 | # Still if append only mode is enabled Redis will load the data from the 192 | # log file at startup ignoring the dump.rdb file. 193 | # 指定是否在每次更新操作后进行日志记录,Redis在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。 194 | # 因为redis本身同步数据文件是按上面save条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为no 195 | # IMPORTANT: Check the BGREWRITEAOF to check how to rewrite the append 196 | # log file in background when it gets too big. 197 | 198 | appendonly yes 199 | 200 | # 指定更新日志文件名,默认为appendonly.aof 201 | # appendfilename appendonly.aof 202 | 203 | # The fsync() call tells the Operating System to actually write data on disk 204 | # instead to wait for more data in the output buffer. Some OS will really flush 205 | # data on disk, some other OS will just try to do it ASAP. 206 | 207 | # 指定更新日志条件,共有3个可选值: 208 | # no:表示等操作系统进行数据缓存同步到磁盘(快) 209 | # always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全) 210 | # everysec:表示每秒同步一次(折衷,默认值) 211 | 212 | appendfsync everysec 213 | # appendfsync no 214 | 215 | # When the AOF fsync policy is set to always or everysec, and a background 216 | # saving process (a background save or AOF log background rewriting) is 217 | # performing a lot of I/O against the disk, in some Linux configurations 218 | # Redis may block too long on the fsync() call. Note that there is no fix for 219 | # this currently, as even performing fsync in a different thread will block 220 | # our synchronous write(2) call. 221 | # 222 | # In order to mitigate this problem it's possible to use the following option 223 | # that will prevent fsync() from being called in the main process while a 224 | # BGSAVE or BGREWRITEAOF is in progress. 225 | # 226 | # This means that while another child is saving the durability of Redis is 227 | # the same as "appendfsync none", that in pratical terms means that it is 228 | # possible to lost up to 30 seconds of log in the worst scenario (with the 229 | # default Linux settings). 230 | # 231 | # If you have latency problems turn this to "yes". Otherwise leave it as 232 | # "no" that is the safest pick from the point of view of durability. 233 | no-appendfsync-on-rewrite no 234 | 235 | # Automatic rewrite of the append only file. 236 | # Redis is able to automatically rewrite the log file implicitly calling 237 | # BGREWRITEAOF when the AOF log size will growth by the specified percentage. 238 | # 239 | # This is how it works: Redis remembers the size of the AOF file after the 240 | # latest rewrite (or if no rewrite happened since the restart, the size of 241 | # the AOF at startup is used). 242 | # 243 | # This base size is compared to the current size. If the current size is 244 | # bigger than the specified percentage, the rewrite is triggered. Also 245 | # you need to specify a minimal size for the AOF file to be rewritten, this 246 | # is useful to avoid rewriting the AOF file even if the percentage increase 247 | # is reached but it is still pretty small. 248 | # 249 | # Specify a precentage of zero in order to disable the automatic AOF 250 | # rewrite feature. 251 | 252 | auto-aof-rewrite-percentage 100 253 | auto-aof-rewrite-min-size 64mb 254 | 255 | ################################## SLOW LOG ################################### 256 | 257 | # The Redis Slow Log is a system to log queries that exceeded a specified 258 | # execution time. The execution time does not include the I/O operations 259 | # like talking with the client, sending the reply and so forth, 260 | # but just the time needed to actually execute the command (this is the only 261 | # stage of command execution where the thread is blocked and can not serve 262 | # other requests in the meantime). 263 | # 264 | # You can configure the slow log with two parameters: one tells Redis 265 | # what is the execution time, in microseconds, to exceed in order for the 266 | # command to get logged, and the other parameter is the length of the 267 | # slow log. When a new command is logged the oldest one is removed from the 268 | # queue of logged commands. 269 | 270 | # The following time is expressed in microseconds, so 1000000 is equivalent 271 | # to one second. Note that a negative number disables the slow log, while 272 | # a value of zero forces the logging of every command. 273 | slowlog-log-slower-than 10000 274 | 275 | # There is no limit to this length. Just be aware that it will consume memory. 276 | # You can reclaim memory used by the slow log with SLOWLOG RESET. 277 | slowlog-max-len 1024 278 | 279 | ################################ VIRTUAL MEMORY ############################### 280 | 281 | ### WARNING! Virtual Memory is deprecated in Redis 2.4 282 | ### The use of Virtual Memory is strongly discouraged. 283 | 284 | ### WARNING! Virtual Memory is deprecated in Redis 2.4 285 | ### The use of Virtual Memory is strongly discouraged. 286 | 287 | # Virtual Memory allows Redis to work with datasets bigger than the actual 288 | # amount of RAM needed to hold the whole dataset in memory. 289 | # In order to do so very used keys are taken in memory while the other keys 290 | # are swapped into a swap file, similarly to what operating systems do 291 | # with memory pages. 292 | # 指定是否启用虚拟内存机制,默认值为no, 293 | # VM机制将数据分页存放,由Redis将访问量较少的页即冷数据swap到磁盘上,访问多的页面由磁盘自动换出到内存中 294 | # 把vm-enabled设置为yes,根据需要设置好接下来的三个VM参数,就可以启动VM了 295 | # vm-enabled no 296 | # vm-enabled yes 297 | 298 | # This is the path of the Redis swap file. As you can guess, swap files 299 | # can't be shared by different Redis instances, so make sure to use a swap 300 | # file for every redis process you are running. Redis will complain if the 301 | # swap file is already in use. 302 | # 303 | # Redis交换文件最好的存储是SSD(固态硬盘) 304 | # 虚拟内存文件路径,默认值为/tmp/redis.swap,不可多个Redis实例共享 305 | # *** WARNING *** if you are using a shared hosting the default of putting 306 | # the swap file under /tmp is not secure. Create a dir with access granted 307 | # only to Redis user and configure Redis to create the swap file there. 308 | # vm-swap-file /tmp/redis.swap 309 | 310 | # With vm-max-memory 0 the system will swap everything it can. Not a good 311 | # default, just specify the max amount of RAM you can in bytes, but it's 312 | # better to leave some margin. For instance specify an amount of RAM 313 | # that's more or less between 60 and 80% of your free RAM. 314 | # 将所有大于vm-max-memory的数据存入虚拟内存,无论vm-max-memory设置多少,所有索引数据都是内存存储的(Redis的索引数据就是keys) 315 | # 也就是说当vm-max-memory设置为0的时候,其实是所有value都存在于磁盘。默认值为0 316 | # vm-max-memory 0 317 | 318 | # Redis swap文件分成了很多的page,一个对象可以保存在多个page上面,但一个page上不能被多个对象共享,vm-page-size是要根据存储的数据大小来设定的。 319 | # 建议如果存储很多小对象,page大小最后设置为32或64bytes;如果存储很大的对象,则可以使用更大的page,如果不确定,就使用默认值 320 | # vm-page-size 32 321 | 322 | # 设置swap文件中的page数量由于页表(一种表示页面空闲或使用的bitmap)是存放在内存中的,在磁盘上每8个pages将消耗1byte的内存 323 | # swap空间总容量为 vm-page-size * vm-pages 324 | # 325 | # With the default of 32-bytes memory pages and 134217728 pages Redis will 326 | # use a 4 GB swap file, that will use 16 MB of RAM for the page table. 327 | # 328 | # It's better to use the smallest acceptable value for your application, 329 | # but the default is large in order to work in most conditions. 330 | # vm-pages 134217728 331 | 332 | # Max number of VM I/O threads running at the same time. 333 | # This threads are used to read/write data from/to swap file, since they 334 | # also encode and decode objects from disk to memory or the reverse, a bigger 335 | # number of threads can help with big objects even if they can't help with 336 | # I/O itself as the physical device may not be able to couple with many 337 | # reads/writes operations at the same time. 338 | # 设置访问swap文件的I/O线程数,最后不要超过机器的核数,如果设置为0,那么所有对swap文件的操作都是串行的,可能会造成比较长时间的延迟,默认值为4 339 | # vm-max-threads 4 340 | 341 | ############################### ADVANCED CONFIG ############################### 342 | 343 | # Hashes are encoded in a special way (much more memory efficient) when they 344 | # have at max a given numer of elements, and the biggest element does not 345 | # exceed a given threshold. You can configure this limits with the following 346 | # configuration directives. 347 | # 指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法 348 | # hash-max-zipmap-entries 512 349 | # hash-max-zipmap-value 64 350 | 351 | # Similarly to hashes, small lists are also encoded in a special way in order 352 | # to save a lot of space. The special representation is only used when 353 | # you are under the following limits: 354 | list-max-ziplist-entries 512 355 | list-max-ziplist-value 64 356 | 357 | # Sets have a special encoding in just one case: when a set is composed 358 | # of just strings that happens to be integers in radix 10 in the range 359 | # of 64 bit signed integers. 360 | # The following configuration setting sets the limit in the size of the 361 | # set in order to use this special memory saving encoding. 362 | set-max-intset-entries 512 363 | 364 | # Similarly to hashes and lists, sorted sets are also specially encoded in 365 | # order to save a lot of space. This encoding is only used when the length and 366 | # elements of a sorted set are below the following limits: 367 | zset-max-ziplist-entries 128 368 | zset-max-ziplist-value 64 369 | 370 | # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in 371 | # order to help rehashing the main Redis hash table (the one mapping top-level 372 | # keys to values). The hash table implementation redis uses (see dict.c) 373 | # performs a lazy rehashing: the more operation you run into an hash table 374 | # that is rhashing, the more rehashing "steps" are performed, so if the 375 | # server is idle the rehashing is never complete and some more memory is used 376 | # by the hash table. 377 | # 378 | # The default is to use this millisecond 10 times every second in order to 379 | # active rehashing the main dictionaries, freeing memory when possible. 380 | # 381 | # If unsure: 382 | # use "activerehashing no" if you have hard latency requirements and it is 383 | # not a good thing in your environment that Redis can reply form time to time 384 | # to queries with 2 milliseconds delay. 385 | # 指定是否激活重置哈希,默认为开启 386 | activerehashing yes 387 | 388 | ################################## INCLUDES ################################### 389 | 390 | # 指定包含其他的配置文件,可以在同一主机上多个Redis实例之间使用同一份配置文件,而同时各实例又拥有自己的特定配置文件 391 | # include /path/to/local.conf 392 | # include /path/to/other.conf 393 | 394 | -------------------------------------------------------------------------------- /database/mysql/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgbnl/laradock/1c33926a670d7af870564dd6907c90f8ff7c1430/database/mysql/.gitkeep -------------------------------------------------------------------------------- /database/redis/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgbnl/laradock/1c33926a670d7af870564dd6907c90f8ff7c1430/database/redis/.gitkeep -------------------------------------------------------------------------------- /docker-compose-dev.yml: -------------------------------------------------------------------------------- 1 | services: 2 | 3 | nginx: 4 | image: ${NGINX} 5 | container_name: nginx 6 | restart: unless-stopped 7 | ports: 8 | - "80:80" 9 | - "443:443" 10 | environment: 11 | - TZ=${TIMEZONE} 12 | volumes: 13 | - ${APP}:${CONTAINER}:rw 14 | - ${CONFIG}/nginx:/etc/nginx/conf.d:ro 15 | networks: 16 | - web 17 | 18 | php: 19 | image: ${PHP} 20 | restart: unless-stopped 21 | container_name: php 22 | user: ${UID}:${GID} 23 | volumes: 24 | - ${APP}:${CONTAINER}:rw 25 | - ${CONFIG}/php/docker-upload.ini:/usr/local/etc/php/conf.d/docker-upload.ini:ro 26 | - ${CONFIG}/php/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro 27 | ports: 28 | - "9000:9000" 29 | depends_on: 30 | - nginx 31 | networks: 32 | - web 33 | 34 | php_seven: 35 | image: ${PHP_SEVEN} 36 | restart: unless-stopped 37 | container_name: php_seven 38 | user: ${UID}:${GID} 39 | volumes: 40 | - ${APP}:${CONTAINER}:rw 41 | - ${CONFIG}/php/docker-upload.ini:/usr/local/etc/php/conf.d/docker-upload.ini:ro 42 | - ${CONFIG}/php/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro 43 | ports: 44 | - "9001:9000" 45 | depends_on: 46 | - nginx 47 | networks: 48 | - web 49 | 50 | mysql: 51 | image: ${MYSQL} 52 | container_name: mysql 53 | restart: unless-stopped 54 | expose: 55 | - "3306" 56 | ports: 57 | - "3306:3306" 58 | environment: 59 | - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} 60 | - MYSQL_DATABASE=${MYSQL_DATABASE} 61 | - MYSQL_USER=${MYSQL_USER} 62 | - MYSQL_PASSWORD=${MYSQL_PASSWORD} 63 | - TZ=${TIMEZONE} 64 | volumes: 65 | - ${DATABASE}/mysql-8-4:/var/lib/mysql:rw 66 | command: 67 | --lower_case_table_names=${LOWER_CASE_TABLE_NAMES} 68 | --character-set-server=${CHARACTER_SET_SERVER} 69 | --collation-server=${COLLATION_SERVER} 70 | --explicit_defaults_for_timestamp=${EXPLICIT_DEFAULTS_FOR_TIMESTAMP} 71 | --default-storage-engine=${DEFAULT_STORAGE_ENGINE} 72 | --sql_mode=${SQL_MODE} 73 | networks: 74 | - web 75 | 76 | mysql_five: 77 | image: ${MYSQL_FIVE} 78 | container_name: mysql_five 79 | restart: unless-stopped 80 | expose: 81 | - "3306" 82 | ports: 83 | - "3307:3306" 84 | environment: 85 | - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} 86 | - MYSQL_DATABASE=${MYSQL_DATABASE} 87 | - MYSQL_USER=${MYSQL_USER} 88 | - MYSQL_PASSWORD=${MYSQL_PASSWORD} 89 | - TZ=${TIMEZONE} 90 | volumes: 91 | - ${DATABASE}/mysql-5-7:/var/lib/mysql:rw 92 | command: 93 | --default-authentication-plugin=${DEFAULT_AUTHENTICATION_PLUGIN} 94 | --character-set-server=${CHARACTER_SET_SERVER} 95 | --collation-server=${COLLATION_SERVER} 96 | --explicit_defaults_for_timestamp=${EXPLICIT_DEFAULTS_FOR_TIMESTAMP} 97 | --lower_case_table_names=${LOWER_CASE_TABLE_NAMES} 98 | networks: 99 | - web 100 | 101 | redis: 102 | image: ${REDIS} 103 | container_name: redis 104 | restart: unless-stopped 105 | ports: 106 | - "6379:6379" 107 | command: redis-server /usr/local/etc/redis/redis.conf 108 | environment: 109 | - TZ=${TIMEZONE} 110 | volumes: 111 | - ${CONFIG}/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro 112 | - ${DATABASE}/redis:/data:rw 113 | - ${STORAGE}/logs/redis/redis.log:/var/log/redis.log:rw 114 | networks: 115 | - web 116 | 117 | networks: 118 | web: 119 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | 4 | nginx: 5 | image: ${NGINX} 6 | container_name: nginx 7 | restart: unless-stopped 8 | ports: 9 | - "80:80" 10 | - "443:443" 11 | environment: 12 | - TZ=${TIMEZONE} 13 | volumes: 14 | - ${APP}:${CONTAINER}:ro 15 | - ${CONFIG}/nginx:/etc/nginx/conf.d:ro 16 | networks: 17 | - web 18 | 19 | php: 20 | image: ${PHP} 21 | restart: unless-stopped 22 | container_name: php 23 | user: ${UID}:${GID} 24 | volumes: 25 | - ${APP}:${CONTAINER}:rw 26 | - ${CONFIG}/php/docker-upload.ini:/usr/local/etc/php/conf.d/docker-upload.ini:ro 27 | - ${CONFIG}/php/www.conf:/usr/local/etc/php-fpm.d/www.conf:ro 28 | ports: 29 | - "9000:9000" 30 | - "8000:8000" 31 | depends_on: 32 | - nginx 33 | networks: 34 | - web 35 | 36 | mysql: 37 | image: ${MYSQL} 38 | container_name: mysql 39 | restart: unless-stopped 40 | expose: 41 | - "3306" 42 | ports: 43 | - "3306:3306" 44 | environment: 45 | - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} 46 | - MYSQL_DATABASE=${MYSQL_DATABASE} 47 | - MYSQL_USER=${MYSQL_USER} 48 | - MYSQL_PASSWORD=${MYSQL_PASSWORD} 49 | - TZ=${TIMEZONE} 50 | volumes: 51 | - ${DATABASE}/mysql:/var/lib/mysql:rw 52 | command: 53 | --lower_case_table_names=${LOWER_CASE_TABLE_NAMES} 54 | --character-set-server=${CHARACTER_SET_SERVER} 55 | --collation-server=${COLLATION_SERVER} 56 | --explicit_defaults_for_timestamp=${EXPLICIT_DEFAULTS_FOR_TIMESTAMP} 57 | --default-storage-engine=${DEFAULT_STORAGE_ENGINE} 58 | --sql_mode=${SQL_MODE} 59 | networks: 60 | - web 61 | 62 | redis: 63 | image: ${REDIS} 64 | container_name: redis 65 | restart: unless-stopped 66 | ports: 67 | - "6379:6379" 68 | command: redis-server /usr/local/etc/redis/redis.conf 69 | environment: 70 | - TZ=${TIMEZONE} 71 | volumes: 72 | - ${CONFIG}/redis/redis.conf:/usr/local/etc/redis/redis.conf:ro 73 | - ${DATABASE}/redis:/data:rw 74 | - ${STORAGE}/logs/redis/redis.log:/var/log/redis.log:rw 75 | networks: 76 | - web 77 | 78 | networks: 79 | web: 80 | -------------------------------------------------------------------------------- /storage/logs/redis/redis.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xgbnl/laradock/1c33926a670d7af870564dd6907c90f8ff7c1430/storage/logs/redis/redis.log --------------------------------------------------------------------------------