Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在nginx上通过php fpm运行Docker Wordpress?_Wordpress_Docker_Nginx - Fatal编程技术网

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

如何在nginx上通过php fpm运行Docker Wordpress?,wordpress,docker,nginx,Wordpress,Docker,Nginx,嘿,我尝试了不同的方法,但它们导致我进入nginx开始页面,错误403或错误404。我目前运行的Wordpress没有php fpm,但它工作得不太好,所以我想更改它,但我只是在运行时遇到了问题 我的Wordpress Docker compose(不含db): 我的nginx撰写文件: services: nginx: restart: always container_name: nginx image: cptdaydreamer/nginx:latest

嘿,我尝试了不同的方法,但它们导致我进入nginx开始页面,错误403或错误404。我目前运行的Wordpress没有php fpm,但它工作得不太好,所以我想更改它,但我只是在运行时遇到了问题

我的Wordpress Docker compose(不含db):

我的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,但您没有提供证书路径

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

其次,在
location/
块中,我有一个
try\u文件$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\u pass 127.0.0.1:9000将有所不同,在您的情况下,
wordpress:9000

我使用的是Cloudflare SSL证书,这是正确的。我已经在http部分定义了它。我的其他容器,如matomo、nextcloud等,在443上可以很好地使用配置来监听。那么,端口80上的监听到底是什么意思?那么,在端口80上需要监听的位置和内容是什么?我将把http部分添加到问题中。如果我删除了索引和根目录,我只欢迎使用nginx!。否则我得到的目录索引“/usr/share/nginx/html/”是禁止的,这也是错误的。我知道了,目录用户的uid是什么?您可以尝试链接到此文件夹
root/usr/share/nginx/html/
,该文件夹应为
www-data
所有,如果您的路径错误。我错过了一个教程,现在我进入了起始页,但13:每一张图片和wp内容的内容都被拒绝。
    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;
    }