【发布时间】:2020-10-24 22:24:27
【问题描述】:
嘿,我尝试了不同的方法,但它们将我引导到 nginx 起始页,错误 403 或错误 404。我目前正在运行没有 php-fpm 的 Wordpress,但它效果不佳,所以我想更改它,但我只做的时候遇到了问题。
我的 Wordpress Docker-compose(无 db):
wordpress:
container_name: wordpress
links:
- wordpress-db
depends_on:
- wordpress-db
image: wordpress:php7.4-fpm
ports:
- 9000:9000
restart: always
volumes:
- /media/storage/wordpress:/var/www/html
- .secrets/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
networks:
- wordpress
environment:
- TZ=Europe/Berlin
env_file:
- .secrets/wordpress.env
我的 nginx 撰写文件:
services:
nginx:
restart: always
container_name: nginx
image: cptdaydreamer/nginx:latest
ports:
- 80:80
- 443:443
- 4443:4443
volumes:
- /media/storage/log:/var/log/nginx
- /etc/ssl:/etc/ssl
external_links:
- wordpress
environment:
- TZ=Europe/Berlin
build:
context: /media/storage/nginx
dockerfile: Dockerfile
networks:
- nextcloudpi
- wordpress
- matomo
- php
现在是重要的部分。我的 nginx 配置:
http {
server_names_hash_bucket_size 64;
access_log off;
error_log /var/log/nginx/error.log;
autoindex_localtime on;
#more_clear_headers Server;
ssl_certificate /etc/ssl/tld.pem;
ssl_certificate_key /etc/ssl/tld.key;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml application/javascript application/json application/xml application/rss+xml image/svg+xml;
gzip_disable "MSIE [1-6]\.";
proxy_send_timeout 180s;
proxy_read_timeout 180s;
fastcgi_send_timeout 180s;
fastcgi_read_timeout 180s;
server {
listen 80 default_server;
server_name _;
server_name_in_redirect off;
location / {
return 404;
}
}
server {
listen 80;
listen [::]:80;
server_name tld.de cloud.tld.de www.tld.de stats.tld.de;
return 301 https://$host$request_uri;
}
# WordPress
server {
server_name tld.de www.tld.de ts.tld.de;
#access_log /var/log/nginx/wordpress-access.log;
error_log /var/log/nginx/wordpress-error.log;
listen 443 ssl http2;
listen [::]:443 ssl http2;
client_max_body_size 500m;
underscores_in_headers on;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass wordpress:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
我得到的错误例如是这样的:/var/www/html 的目录索引被禁止。
如果我删除 $uri/,例如,我会收到错误 404。我需要做什么才能让我的实例运行?但我是对的,我可以使用我现有的 wordpress 实例,并且只有访问它的方式会改变?
【问题讨论】: