繁体   English   中英

如何在 nginx 上通过 php-fpm 运行 Docker Wordpress?

[英]How to run Docker Wordpress through php-fpm on nginx?

嘿,我尝试了不同的东西,但它们将我带到了 nginx 起始页,错误 403 或错误 404。我目前正在运行没有 php-fpm 的 Wordpress,但它的效果不是很好,所以我想更改它,但我只遇到了问题正在做。

我的 Wordpress Docker-compose(不带数据库):

  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 实例,并且只有访问它的方式会发生变化吗?

您正在收听 ssl,但尚未提供证书路径?

您是否碰巧使用过 Cloudflare 等任何外部 ssl 提供商? 如果是,那么您必须侦听端口 80(这是 Cloudflare 的默认端口)或在 Cloudflare 上设置以获取 https 站点,在这种情况下,您还需要提供自己的证书路径。

其次在你的location /块中,我有这个try_files $uri $uri/ /index.php?url=$uri; ,以及其他一些设置

    location / {
      try_files $uri $uri/ /index.php?url=$uri;
    }
    location ~ \.(php)$ {
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
      fastcgi_read_timeout 3000;
      proxy_connect_timeout 3000s;
      proxy_send_timeout   3000;
      proxy_read_timeout   3000;
    }

fastcgi_pass 127.0.0.1:9000会有所不同,在你的情况下是wordpress:9000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM