标签 wordpress 下的文章

背景

为了方便,使用了docker部署了wordpress,通过nginx进行反向代理,并配置了域名,安装完成一切正常,但是在上传主题是出现了如下错误提示:

413 Request Entity Too Large

百度google一通后,在http{}中加入 client_max_body_size 10m;解决了。

然后上传文件,确出现了另一个错误提示:

The uploaded file exceeds the upload_max_filesize directive in php.ini.

解决方案

很明显,这是php上的限制,只需要修改php.in即可。
为了方便修改,我们在创建容器时,添加volumes将php配置映射到本地,完整的docker-compose.yml如下:

version: '3'
services:
  wordpress:
    image: wordpress:latest
    container_name: wordpress
    restart: always
    ports:
      - "9102:80"
    volumes:
      - ./html:/var/www/html
      - ./php:/usr/local/etc/php
    environment:
      WORDPRESS_DB_HOST: 10.0.4.5:3306
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: 123456
      WORDPRESS_DB_NAME: wp_demo

启动容器后,将php文件夹中的php.ini-production文件拷贝一份更名为:php.ini,编辑该文件,修改其中的upload_max_filesize项目的值,如下:

upload_max_filesize = 20M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

重启容器,即可解决问题。

背景

在云服务器上搭建了wordpress,为了方便部署,采用了docker方式,使用了9102的端口号。然后通过nginx进行反向代理,使用域名访问。

问题

nginx配置很简单,直接使用了proxy_pass配置到docker容器的wordpress地址,如下:

server {
    listen 80;
    server_name www.我的域名.com;
    location / {
        proxy_pass http://10.0.4.6:9102;
        proxy_set_header Host $host;
        proxy_set_header X-Forward-For $remote_addr;
        proxy_redirect off;
    }
}

配置完成后,访问域名进行安装,配置,都正常。管理后台也可正常访问。但是想要进入博客首页时,出了问题,直接跳转到了http://10.0.4.6:9102。很明显,这个地址是无法访问也是不对的。
总结下问题:域名+/其他页面的形式是可以正常访问的,但是如果只有域名来访问首页就会出现301重定向问题。

Request URL: http://我的域名.com/
Request Method: GET
Status Code: 301 Moved Permanently (from disk cache)
Remote Address: 127.0.0.1:8889
Referrer Policy: strict-origin-when-cross-origin

Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Thu, 19 Aug 2021 06:42:17 GMT
Location: http://10.0.4.5/
Server: nginx/1.21.1
X-Powered-By: PHP/7.4.22
X-Redirect-By: WordPress

解决方案:

多方查找,找到了方案,安装如下配置进行设置,即可解决。

server {
    listen       80;
    server_name  我的域名.com;
    
    set $node_port 9102;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://10.0.4.5:$node_port$request_uri;
        proxy_redirect off;
    }
}