Closed lhuanyun closed 1 year ago
我用的是apache镜像,但是用的nginx反向代理。具体操作可参考https://lisper517.top/index.php/archives/22/,3.实战:编写易移植的typecho并使用https一节。使用docker-compose管理mysql、nginx、joyqi/typecho:nightly-php8.0-apache镜像。
version: "3.8"
# install mariadb latest
services:
db:
image: mariadb:latest
container_name: mariadb
volumes:
- ./db_data:/var/lib/mysql
restart: always
environment:
TZ: "Asia/Shanghai"
MYSQL_ROOT_PASSWORD: root-passowrd
MYSQL_DATABASE: database-name
MYSQL_USER: database-username
MYSQL_PASSWORD: user-password
# 可以改成你需要的fpm镜像
typecho:
depends_on:
- db
image: joyqi/typecho:nightly-php8.0-fpm
container_name: typecho
ports:
- 127.0.0.1:9000:9000
restart: always
environment:
TIMEZONE: "Asia/Shanghai"
volumes:
- /var/www/typecho:/app
# Declare volumes
volumes:
db_data:
typecho:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.org;
root /var/www/typecho;
index index.html index.php;
# Typecho static url
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
}
location ~ /\. {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# 按需求添加更多的文件扩展名
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|webp|tiff?|woff|woff2|svg|tff)$ {
# 静态文件直接从 volume 到宿主机的路径获取
root /var/www/typecho;
try_files $uri $uri/ 404;
expires max;
access_log off;
log_not_found off;
}
location ~ [^/]\.php(/|$) {
# 使用/app 否则nginx会报错 "Primary script unknown"
# 如果未来官方的docker容器的路径不是/app,那么需要修改成未来的路径
root /app;
fastcgi_param HTTP_PROXY "";
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_hide_header X-Powered-By;
# https://www.nginx.com/resources/wiki/start/topics/examples/fastcgiexample/#secure-your-upload-directory
# To secure the uploads folder
if ($uri !~ "^/uploads/") {
fastcgi_pass 127.0.0.1:9000; # 与docker-compose文件里的 127.0.0.1:9000一致
}
}
}
上线后,安装时,数据库的地址使用 "db" 不带引号。
docker-compose.yaml
version: "3.8" # install mariadb latest services: db: image: mariadb:latest container_name: mariadb volumes: - ./db_data:/var/lib/mysql restart: always environment: TZ: "Asia/Shanghai" MYSQL_ROOT_PASSWORD: root-passowrd MYSQL_DATABASE: database-name MYSQL_USER: database-username MYSQL_PASSWORD: user-password # 可以改成你需要的fpm镜像 typecho: depends_on: - db image: joyqi/typecho:nightly-php8.0-fpm container_name: typecho ports: - 127.0.0.1:9000:9000 restart: always environment: TIMEZONE: "Asia/Shanghai" volumes: - /var/www/typecho:/app # Declare volumes volumes: db_data: typecho:
Nginx conf 443部分
server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name example.org; root /var/www/typecho; index index.html index.php; # Typecho static url if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } location ~ /\. { deny all; } location / { try_files $uri $uri/ /index.php?$args; } # 按需求添加更多的文件扩展名 location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|webp|tiff?|woff|woff2|svg|tff)$ { # 静态文件直接从 volume 到宿主机的路径获取 root /var/www/typecho; try_files $uri $uri/ 404; expires max; access_log off; log_not_found off; } location ~ [^/]\.php(/|$) { # 使用/app 否则nginx会报错 "Primary script unknown" # 如果未来官方的docker容器的路径不是/app,那么需要修改成未来的路径 root /app; fastcgi_param HTTP_PROXY ""; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_hide_header X-Powered-By; # https://www.nginx.com/resources/wiki/start/topics/examples/fastcgiexample/#secure-your-upload-directory # To secure the uploads folder if ($uri !~ "^/uploads/") { fastcgi_pass 127.0.0.1:9000; # 与docker-compose文件里的 127.0.0.1:9000一致 } } }
上线后,安装时,数据库的地址使用 "db" 不带引号。
谢谢你
有没有详细一点,关于docker 下joyqi/typecho:nightly-php7.4-fpm 与主机nginx或者docker里nginx的配置实现呢? 我的设备是arm64,想节省点资源,所以使用nginx。多次尝试,均出现错误。 想知道大家怎么配置。谢谢