大网数据广告活动
服务器运维问答

Setup wordpress container in subdirectory with nginx and mariadb

· 52CE 我爱测

Ok guys here is the problem: i have my webserver serving a website, a cms and mobile app api using a subdirectory approach like this localhost -> site localhost/cms localhost/api everything is built using docker compose services:…

问题原文

原帖链接 · javal88 · CC BY-SA 3.0

Ok guys here is the problem: i have my webserver serving a website, a cms and mobile app api using a subdirectory approach like this

  • localhost -> site
  • localhost/cms
  • localhost/api

everything is built using docker compose

services:
  server:
    build: ./docker/nginx
    links:
      - fpm
    ports:
      - 80:80
      - 443:443

  fpm:
    build: ./docker/php
    links:
      - database
      - smtp

  database:
    build: ./docker/mariadb
    volumes:
      - dbdata:/var/lib/mysql

volumes:
  dbdata:

What i'd like to do is to add 2 new containers: one for wordpress and one for the wordpress db in order to proxy pass every request to mydomain.dom/blog to the wordpress container. I was able to pass the request using a nginx config like below but unfortunately i'm fighting with the container which keeps redirecting everything to localhost instead of localhost/blog, i think i'm missing some config in wordpress.

location /blog/ {
    proxy_http_version 1.1;
    proxy_buffering off;
    proxy_read_timeout    90;
    proxy_connect_timeout 90;
    proxy_redirect        off;
    proxy_pass http://blog:80; # the wordpress container name

    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $proxy_connection;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
    proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
    proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;

    # Mitigate httpoxy attack (see README for details)
   proxy_set_header Proxy "";
}

# Cms stuff
location /cms/ {
    try_files $uri $uri/ /staff/index.php?$args;

    include _php.conf; # php-fpm setup
}

# Site stuff
location / {

    try_files $uri $uri/ /index.php?$args;

    include _php.conf; # php-fpm setup
}

已采纳解答

原帖链接 · Luca Gibelli · CC BY-SA 4.0

You need to tell WordPress the new base URL to use. The easiest way to do it is to add the following two lines to wp-config.php in wordpress base dir:

define('WP_HOME','http://example.com/blog');
define('WP_SITEURL','http://example.com/blog');

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-26)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。