指向 ip 而不是文件夹的 nginx 位置

nginx location pointing to an ip instead of a folder

所以我在 laravel in http://example.com sitting on server-A having a 111.111.111.111 ip and I have a wordpress 上有一个网站 运行 坐在 server-B222.222.222.222

我想要它,这样我就可以通过 http://example.com/mywordpress

访问我的 wordpress

我怎样才能做到这一点?我尝试使用谷歌搜索,但我似乎无法找到正确的关键字

现在这是我能想到的最好的事情

# my nginx conf

location /mywordpress {
  proxy_pass http://mywordpress.example.com/; //already set the 222.222.222.222 to server-B
}

尝试这样的事情:

http {

    upstream wordpress {
         server 222.222.222.222:80 max_fails=2  fail_timeout=3s;
    }

    server {

        listen 80;

        server_name example.com;

        location /mywordpress {
             rewrite /mywordpress(.*) /  break;
             proxy_pass http://wordpress
        }
    }
}

假设您在服务器 A

上有一个 /etc/nginx/sites-available/example.com

打开并添加这一行:

location /mywordpress {
    proxy_pass http://222.222.222.222/mywordpress;
    proxy_set_header Host $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;
}

之后

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

在服务器-B 假设您在根目录 /var/www/html 上安装了 wordpress,并且只存在 wordpress 文件

遵循本指南https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory

新建目录/var/www/html/mywordpress

将所有文件从 /var/www/html 移动到 /var/www/html/mywordpress

将 index.php 和 .htaccess 从 mywordpress 目录复制到您的 html 文件夹

编辑 /var/www/html/index.php

require( dirname( __FILE__ ) . '/wp-blog-header.php' );

require( dirname( __FILE__ ) . '/mywordpress/wp-blog-header.php' );

现在,尝试访问您的新示例。com/mywordpress