简体   繁体   English

Nginx 反向代理深度链接 Wordpress on Docker

[英]Nginx reverse proxy deeplinks Wordpress on Docker

I'm trying to run Wordpress on Digital Ocean through Docker. Things started out well, I had it up and running in no time configured like so:我正在尝试通过 Docker 在 Digital Ocean 上运行 Wordpress。一切顺利,我很快就启动并运行了它,如下所示:

version: '3.3'
services:
    wordpress:
        depends_on:
            - db
        image: wordpress:5.5.1-php7.2-apache
        container_name: wp
        restart: always
        volumes:
            - ./www/wp-content:/var/www/html/wp-content
        environment:
            WORDPRESS_DB_HOST: db:3306
            WORDPRESS_DB_PASSWORD: ${DB_PWD}
        ports:
            - 3010:80
        networks:
            - network
    db:
        image: mysql:5.7
        container_name: db
        restart: always
        volumes:
            - ./dbdata:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: ${DB_PWD}
        networks:
            - network
    phpmyadmin:
        depends_on:
            - db
        image: phpmyadmin/phpmyadmin
        container_name: pma
        restart: always
        ports:
            - 3011:80
        environment:
            PMA_HOST: db
            MYSQL_ROOT_PASSWORD: ${DB_PWD}
            UPLOAD_LIMIT: 20000000
        networks:
            - network
networks:
    network:
volumes:
    db_data:

On the Digital Ocean droplet I configured Nginx as a reverse proxy:在 Digital Ocean droplet 上,我将 Nginx 配置为反向代理:

server {
    listen 80;
    listen [::]:80;

    server_name my.test.url;

    location / {
        rewrite /(.*) /$1 break;
        proxy_pass http://localhost:3010;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }
}

I already had my.test.url pointing to the droplet's IP. I updated the 'siteurl' and 'home' records in the wp_options table in the database to my.test.url我已经有 my.test.url 指向 droplet 的 IP。我将数据库中 wp_options 表中的 'siteurl' 和 'home' 记录更新为 my.test.url

This all worked well, serving the homepage if I visit my.test.url.这一切都运行良好,如果我访问 my.test.url,就会为主页提供服务。 However when I visit a deep link, like my.test.url/example I get redirected to 127.0.0.1/example where obviously nothing is running.然而,当我访问一个深层链接时,比如 my.test.url/example 我被重定向到 127.0.0.1/example ,显然没有任何东西在运行。

I don't know how to proceed;我不知道如何进行; I thought setting the rewrite rule in the nginx config would do the trick but alas..我认为在 nginx 配置中设置重写规则可以解决问题,但唉......

I should mention I want to run multiple sites on the Digital Ocean droplet, each serving from their own port, so 'just' serving from port 80 is not an option.我应该提一下,我想在 Digital Ocean droplet 上运行多个站点,每个站点都从自己的端口提供服务,因此“仅”从端口 80 提供服务不是一种选择。

Can anyone point me in the right direction?谁能指出我正确的方向?

As it turns out, the above configuration was correct;事实证明,上面的配置是正确的; the problem was a DNS error combined with Wordpress permalink settings that dictated a trailing slash after the post name.问题是 DNS 错误与 Wordpress 永久链接设置相结合,该设置指示帖子名称后的尾部斜杠。 This caused a DNS lookup on the server that failed, resulting in the redirect to 127.0.0.1...这导致服务器上的 DNS 查找失败,导致重定向到 127.0.0.1...

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

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