jueves, 2 de enero de 2014

FAQ #003: ¿How to use the apache on OSX?

In this post I will copy some useful commands to run httpd on OSX. We have already installed the apache, but we need excet it with sudo, so, here we go, let´s start de apache:

$ sudo apachectl start

and in the browser, we can verify it with the address localhost on default port 80:

http://localhost

 $ sudo apachectl stop

An the apache is down;

So, next step: ¿Can we define a reverse proxy? ¿Where the httpd.conf is located?

The dafault location is

/etc/apache2/httpd.conf
we can see some basic default configuration of httpd on mac:



In httpd.conf we are going to se virtual host references, in a separate file

# Virtual hosts

Include /private/etc/apache2/extra/httpd-vhosts.conf
Also, we uncomment :

LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

Before edit any configuration, it is a good idea to make a backup, for example, httpd.conf.mybak

Let´s try the following directive in the httpd.con to enable a simple Reverse Proxy

ProxyPass        "/server/"  "http://localhost:3000/"
ProxyPassReverse "/server/"  "http://localhost:3000/"
ProxyPass        "/client/"  "http://localhost:3001/"
ProxyPassReverse "/client/"  "http://localhost:3001/"
And let´s try the following URLS, which should be equivalents:

http://localhost/clients
http://localhost:3001

http://localhost/server/usarios
http://localhost:3000/usuarios

And we can see the same json response, from the same resource, with o without reverse proxy:



What is the utility for this config? It is a way to avoid problems of cross domain when we are testing a web application with a different port on front and backends. And the XMLHttpRequest can´t work fine....

Ok, let´s close this post. and we know a little more about use apache httpd and reverse proxy con OSX.

Go on, and do the next wave :)






0 comentarios:

Publicar un comentario