【问题标题】:How to access all of the subdirectory wordpress with Reverse Proxy?如何使用反向代理访问 wordpress 的所有子目录?
【发布时间】:2021-06-14 14:34:48
【问题描述】:

我在反向代理上的 Wordpress 有一些问题。

到目前为止,这是我的简单 nginx 配置。

 server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  site1.abc;

    location / {
            proxy_set_header   X-Real-IP             $remote_addr;
            proxy_set_header   X-Forwarded-For       $proxy_add_x_forwarded_for;
            proxy_pass http://192.168.1.45:8009/;
    }

我的 wp-config.php

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',         ' N=R*yg% {?,:u*%P?b|B@.#]No Eco`%Wr>T5_6LAPaY#|T%A4%n2Eb>6b4M-F+' );
define( 'SECURE_AUTH_KEY',  'bYNdT{ !4lw&j@7FCylQx{ 1rc(|{Lvq9MzVYgWt1EZ?Udm~ wvXd,Eq:O ~N,D3' );
define( 'LOGGED_IN_KEY',    '/PY2ks,|10T7*^K|?R bM<`5O3$w%f <Xk)YT.aF5ZWHyLD%ju5v`O_12W&GzLsz' );
define( 'NONCE_KEY',        '{B+Fpx]pUzgU(pMgDUm84AaHApsvh.p*2:+Y>7>f1uBR=Omz,s`D}8CW{?sr7Xy&' );
define( 'AUTH_SALT',        '~?+>T0E+>)E{tje{MV(![Fi74B.,iMG5.1cdg`>fzYF[!]/)7&{J[(Ix<NB-zs*%' );
define( 'SECURE_AUTH_SALT', '/J=VF|:Tm%Hk!>b51QMX?f{~,xG6v9$`!OhY)W- rw`vi>,,?}zWB5Ap|DMe?wQu' );
define( 'LOGGED_IN_SALT',   'MM~^^0ERsgDJqDv=73EXIhWrmN0*{C*GKm0%5 c((6T-f!P/5e;qsIg%Ss:@1i.H' );
define( 'NONCE_SALT',       ',A#EHnqxe13pe3i-/LTLWs3GAK?MRa4^B>aV`Pg+ZjlpMCrEz]%odO 11.3:uBq>' );

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://wordpress.org/support/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
        define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';



我的 server_name 域有一个公共 IP 地址,proxy_pass IP 是我的内部 IP。

它有效,但只有主页。当我点击主页时,它会自动将我重定向到外部用户无法访问的内部 IP。

例如:点击“关于”,将我重定向到 http://192.168.1.45/index.php/blog(给我一个错误:“无法访问此站点”)。

我想要:点击“关于”,将我重定向到http://site1.abc/index.php/blog,类似这样。

它不会隐藏我的后端服务器。请帮帮我。

【问题讨论】:

    标签: wordpress nginx-reverse-proxy


    【解决方案1】:

    您的 Wordpress 似乎不知道它位于 site1.abc 并猜测它位于 192.168.1.45,因为它接收具有此地址的请求并且没有主机

    让 Nginx 告诉 Wordpress 该请求是针对 site1.abc 主机的,因此 Wordpress 知道它自己的主机名:将 Host 标头添加到请求 Nginx 代理到 Wordpress 的请求中。

    location / {
                proxy_set_header   X-Real-IP             $remote_addr;
                proxy_set_header   X-Forwarded-For       $proxy_add_x_forwarded_for;
                proxy_pass         http://192.168.1.45:8009/;
                proxy_set_header   Host                  site1.abc
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      相关资源
      最近更新 更多