Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Can anyone give a moderately detailed proxy server flow for making HTTP requests via a hosted javascript app, which is an angularjs/node app hosted on apache server port:3000 in my case. I'm calling an outside service and hitting the cross origin not allowed brick wall. I've seen plenty of examples that recommend using mod_proxy on apache, but they all lack in detail and assume that there's prior basic proxy config knowledge. My assumption is that this is a common problem to overcome, but I need a little hand holding first time around. My primary question are:

  1. Can I achieve this on one server using one IP address or do one server to host and one to mod_proxy with?

  2. If I can do this on one server. If so, what is the generic setup (A to B)? One or two virtual hosts?

  3. Explain the ProxyPass and ProxyReversePass directives. Do I need to add my outside service URL here?

  4. Am I just going the complete wrong way down a one way street?

share|improve this question

1 Answer 1

Figured it out after a bit of trial and error. Here's what I have...

  1. Can I achieve this on one server using one IP address or do one server to host and one to mod_proxy with?
    A: ON server with one IP address works just fine. All proxy functions are handled via a port which in my case is :9000. The choice of port number is really up to you. 9000 was just a high number and didn't conflict with any other node functions. It also seems to be a unwritten standard from what I can tell.

  2. If I can do this on one server. If so, what is the generic setup (A to B)? One or two virtual hosts?
    A: This is probably best explained by just looking at my Apache virtual host setup...

    Since i'm using SSL, all port :80 HTTP requests are rewritten to HTTPS

    VirtualHost *:80
      RewriteEngine On
      RewriteCond %{HTTPS} off
      RewriteRule (.*) http(s)://%{HTTP_HOST}%{REQUEST_URI}
    /VirtualHost



I'm running a node app on port :3000 so all traffic is routed from the standard :443 to port :3000 and visa versa. Basically port :3000 becomes the primary domain name via a server proxy as far as the public is concerned.

    VirtualHost *:443
      RewriteEngine On
      ProxyRequests Off
      SSLEngine on
      SSLProxyEngine on

      SSLCertificateFile /pathToCert/sslCert.crt
      SSLCertificateKeyFile /pathToKey/sslKey.key

      Location /
          ProxyPass http://localhost:3000/ 
          ProxyPassReverse http://localhost:3000/
      /Location

    /VirtualHost



I've assigned port :9000 as the reverse proxy for my Cross Domain HTTP POST requests. The ProxyPass and ProxyPassReverse directives essentially rewrite the url of HTTP requests I make with an address of my domain.

https://MySite.com:9000/?request&params&here

will become

https://SomeOtherSiteThanMine.com/?request&params&here


Thus fooling the browser into thinking I'm making requests to my own domain. Also notice the "Header set" lines which make the requests CORS compatible with my proxy.

    VirtualHost *:9000
      RewriteEngine On
      ProxyRequests Off

      SSLEngine on
      SSLProxyEngine on

      SSLCertificateFile /pathToCert/sslCert.crt
      SSLCertificateKeyFile /pathToKey/sslKey.key

      ProxyPass / https://SomeOtherSiteThanMine.com/
      ProxyPassReverse / https://SomeOtherSiteThanMine.com/

      Header set Access-Control-Allow-Origin "*"
      Header set Access-Control-Allow-Methods "POST"
    /VirtualHost




3. Explain the ProxyPass and ProxyReversePass directives. Do I need to add my outside service URL here?
A: See above


4. Am I just going the complete wrong way down a one way street?
A: Nope, ended up working out perfectly.


If anyone sees a problem with the method, by all means chime in. I just pieced together a a handful of vaguely described examples.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.