0

As I have created wordpress blog which is hosted in NGINX webserver, and this webserver is running on 8090 port and it is insecure. So to access blog post I need to navigate as http://example.org:8090/blog and http://example.org:8090/blog/wp-admin . and this both link were working fine at my end.But my requirement is to show those page contents from secure domain which is hosted in Node and it is a React based Application which is running on port 80 and 443 port so to make it work I have added http-proxy-middleware node proxy module.

Work Around

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': '' } }))

But when I hit in url as https://example.org/blog it navigates to http://example.org:8090

UIseeker
  • 97
  • 1
  • 11

1 Answers1

0

Looking at the documentation - your pathRewrite option is removing the /blog prefix.

To map /blog to /blog and /blog/wp-admin to /blog/wp-admin, you do not need any pathRewrite, and you can achieve it using a single app.use statement.

Try:

app.use('/blog', proxy('/blog', { target: 'http://example.org:8090', changeOrigin: true }))
Richard Smith
  • 45,711
  • 6
  • 82
  • 81