AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1141685
Accepted
OdifYltsaeb
OdifYltsaeb
Asked: 2023-08-16 19:35:24 +0800 CST2023-08-16 19:35:24 +0800 CST 2023-08-16 19:35:24 +0800 CST

为 WordPress 设置 nginx 的问题

  • 772

我的 /etc/nginx/sites-available/wordpress 中有以下 wordpress nginx 配置:

    index index.html index.htm index.nginx-debian.html;

    location / {
        proxy_pass http://nextjs;
        proxy_http_version 1.1;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            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 $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_pass_request_headers on;
    }


    location /wordpress {
        root /var/www;
        try_files $uri $uri/wordpress/ /wordpress/index.php$is_args?$args;

            location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/run/php/php8.1-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include snippets/fastcgi-php.conf;
                    fastcgi_buffers 1024 4k;
                    fastcgi_buffer_size 128k;
            }
    }

正如您所看到的,WordPress 有一个基于 NextJS 的静态前端。一般来说,它的效果很好。不过,有一个怪癖不起作用,我不确定这是 WordPress 问题还是 Nginx 问题。

  • 当用户导航到 /wordpress 时,我们会看到来自 wordpress 的内容,这很好
  • 当用户导航到 /wordpress/graphql 时,grahpql 端点工作正常
  • 当用户导航到 /wordpress/wp-admin 时,事情就会崩溃。存在重定向循环,brauser 报告该站点未正确重定向等等。
  • 当用户导航到 /wordpress/wp-admin/index.php 时,一切正常。

那么这是从哪里来的呢?这是 Nginx 的事情吗?WordPress 的事?我该如何解决?

编辑1:添加了curl -vvv输出:

C:\Users\alank>curl -vvv https://mydomain.ee/wordpress/wp-admin
*   Trying 194.204.13.171:443...
* Connected to mydomain.ee (194.204.13.171) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server did not agree on a protocol. Uses default.
* using HTTP/1.x
> GET /wordpress/wp-admin HTTP/1.1
> Host: mydomain.ee
> User-Agent: curl/8.0.1
> Accept: */*
>
* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection
* schannel: SSL/TLS connection renegotiated
* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection
* schannel: SSL/TLS connection renegotiated
< HTTP/1.1 302 Found
< server: nginx/1.18.0 (Ubuntu)
< date: Tue, 22 Aug 2023 10:19:10 GMT
< content-type: text/html; charset=UTF-8
< transfer-encoding: chunked
< expires: Wed, 11 Jan 1984 05:00:00 GMT
< cache-control: no-cache, must-revalidate, max-age=0
< link: <https://mydomain.ee/wordpress/wp-json/>; rel="https://api.w.org/"
< x-redirect-by: WordPress
< location: https://mydomain.ee/wordpress/wp-admin/
<
* Connection #0 to host mydomain.ee left intact

编辑2:curl -vvv 带有尾部斜杠:

C:\Users\alank>curl -vvv https://mydomain.ee/wordpress/wp-admin/
*   Trying 194.204.13.171:443...
* Connected to  mydomain.ee (194.204.13.171) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server did not agree on a protocol. Uses default.
* using HTTP/1.x
> GET /wordpress/wp-admin/ HTTP/1.1
> Host: mydomain.ee
> User-Agent: curl/8.0.1
> Accept: */*
>
* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection
* schannel: SSL/TLS connection renegotiated
* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection
* schannel: SSL/TLS connection renegotiated
< HTTP/1.1 302 Found
< server: nginx/1.18.0 (Ubuntu)
< date: Tue, 22 Aug 2023 11:13:01 GMT
< content-type: text/html; charset=UTF-8
< transfer-encoding: chunked
< expires: Wed, 11 Jan 1984 05:00:00 GMT
< cache-control: no-cache, must-revalidate, max-age=0
< link: <https://mydomain.ee/wordpress/wp-json/>; rel="https://api.w.org/"
< x-redirect-by: WordPress
< location: https://mydomain.ee/wordpress/wp-admin/
< 
* Connection #0 to host mydomain.ee left intact
nginx
  • 2 2 个回答
  • 109 Views

2 个回答

  • Voted
  1. Best Answer
    Esa Jokinen
    2023-08-28T22:05:14+08:002023-08-28T22:05:14+08:00

    重定向/wordpress/wp-admin/到自身。

    您是否尝试过使用官方Nginx WordPress文档中的此用例的确切示例?

    在这里,根据您的用例进行修改,不应影响.php外部/wordpress/:

    location /wordpress {
            try_files $uri $uri/ /wordpress/index.php?$args;
    
            location ~ \.php$ {
                    fastcgi_split_path_info ^(/wordpress)(/.*)$;
            }
    }
    

    您的fastcgi_split_path_info建议与此建议不同。

    • 1
  2. alexus
    2023-08-21T21:43:16+08:002023-08-21T21:43:16+08:00

    人们可以尝试在位置块中使用以下内容(可以根据需要随意调整路径),即/wp-admin/index.php?$args根据您的环境/设置:

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

    参考:

    • https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
    • https://wordpress.org/documentation/article/nginx/
    • -1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve