0

因为我创建了托管在 NGINX 网络服务器中的 wordpress 博客,并且该网络服务器在 8090 端口上运行,并且不安全。因此,要访问博客文章,我需要导航为 http://example.org:8090/bloghttp://example.org:8090/blog/wp-admin。这两个链接在我的最后都运行良好。但我的要求是显示来自托管在 Node 中的安全域的页面内容,它是一个基于 React 的应用程序,在端口 80 和 443 端口上运行,以便让它工作我添加了http-proxy-middleware 节点代理模块。

解决问题

app.use('/blog', proxy('/blog', { target: 'http://example.org:8090', changeOrigin: true,
    pathRewrite: { '^/blog': '' } }))   

app.use('/blog/wp-admin', proxy('/blog/wp-admin', { target: 'http://example.org:8090', changeOrigin: true,
    pathRewrite: { '^/blog/wp-admin': '' } }))

但是当我以https://example.org/blog的形式输入 url 时,它会导航到http://example.org:8090

4

1 回答 1

0

查看文档- 您的pathRewrite选择是删除/blog前缀。

要映射/blog/blog/blog/wp-admin/blog/wp-admin您不需要任何pathRewrite,并且可以使用单个app.use语句来实现。

尝试:

app.use('/blog', proxy('/blog', { target: 'http://example.org:8090', changeOrigin: true }))
于 2017-06-15T08:14:42.943 回答