由于我创建了在NGINX网络服务器中托管的wordpress博客,并且这个网络服务器在8090端口上运行并且它是不安全的。因此,要访问博客帖子,我需要导航为http://example.org:8090/blog和http://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点击网址时,它会导航到http://example.org:8090
答案 0 :(得分:0)
查看the documentation - 您的pathRewrite
选项正在删除/blog
前缀。
要将/blog
映射到/blog
和/blog/wp-admin
映射到/blog/wp-admin
,您不需要任何pathRewrite
,并且可以使用单app.use
来实现它1}}陈述。
尝试:
app.use('/blog', proxy('/blog', { target: 'http://example.org:8090', changeOrigin: true }))