I am trying to configure Access-Control-Allow-Origin in Apache to allow certain domains. Below is my httpd configuration
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
But the above config is not doing anything. Heard that we need to enable mod_headers to make it work. I run this httpd -M command and observed that header module is not present in my Apache. Can you anyone pls tell me how to enable?
Here is my solution:
Open the file httpd.conf at "your apache folder"/conf
Find the following line using CTRL+f in your text editor: #LoadModule headers_module modules/mod_headers.so
Remove the #
Save and restart your apache.
I was wondering if anybody can help me set up CORS on my Apache web server. I would appreciate a step-by-step process because many sites online are telling me different things. Like what do I need to do on my httpd.conf or ssl.conf files, where to put my .htaccess file, etc.
The above answer is correct and put Inside the httpd.conf. This should be changed to whatever you set Document Root.
On Ubuntu, httpd.conf is located in the directory /etc/apache2. apache2.conf is also located in /etc/apache2.
On CENTOS 6 httpd.conf in the path /etc/httpd/conf/httpd.
<Directory "/var/www/html">
Header set Access-Control-Allow-Origin "*"
</Directory>
# edit your conf/httpd.conf file. Verify that the headers module is loaded
LoadModule headers_module modules/mod_headers.so
# to whitelist every origin, use
Header set Access-Control-Allow-Origin "*"
More info: http://enable-cors.org/server_apache.html
Premise:
I have a custom webserver running on port 2480. I don't really know how it works, but it has it's own www dir. Inside this dir, there is an index.htm file which is executed by default. Inside that file, there is
<meta http-equiv="refresh" content="0;URL=/studio/index.html">
So, I immediately get redirection to 107.0.0.1:2480/studio/index.html. However, I can't find such "studio" folder anywhere in my filesystem (I have no idea how this works).
Question:
In the same server, I have an Apache webserver running on port 80. I'd like to configure a reverse proxy so that "127.0.0.1:80/foo" is equal to "127.0.0.1:2480".
I did in apache2.conf:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
ProxyPass /foo http://localhost:2480/
ProxyPassReverse /foo http://localhost:2480/
Then, I navigate to "127.0.0.1:80/foo". I see that it correctly connects to "127.0.0.1:2480/index.htm". But then, index.htm immediately redirects to "/studio/index.html", and I see the url changes to "127.0.0.1:80/studio/index.html. I get then "403 forbidden". But this is a "fake forbidden", because doing this it is just looking for "/studio/index.html" in the default apache document root dir, which of course does not exists (and htaccess is configured to deny all by default).
So question is:
"127.0.0.1:80/foo" resolves correctly to "127.0.0.1:2480/index.htm"
"index.htm" redirects to "/studio/index.html"
why is apache looking for "127.0.0.1:80/studio/index.html" instead of "127.0.0.1:2480/studio/index.html" ?
How should this be done?
Thanks a lot
I copied the relevant lines over from another installation but it doesn't work here. I get a 404 generated by the word press that's installed on the server.
<Location /server-status>
SetHandler server-status
Order Allow,Deny
Allow from [my ip]
</Location>
I used to visit http://[old server ip]/server-status and it worked fine. Now I just get a 404 coming out of the wordpress that's installed on the new server.
Is this what happens if the proper mods are not installed in this installation? How can I tell? How can I trouble shoot this? Thanks.
You're probably missing the LoadModule for mod_status. On debian/ubuntu, use a2enmod. If you manage your config directly, just add the LoadModule for mod_status.
The problem was that this config had to go in /etc/apache2/mods-enabled/status.conf
From what I read it seemed to me like it could also go in apache2.conf or the individual site config file but those didn't work for me for some reason.
I am trying to proxy a subdirectory to another server. My httpd.conf:
RewriteEngine On
ProxyPreserveHost On
RewriteRule .*subdir/ https://anotherserver/subdir/ [P]
The problem is that Apache is always logging this:
AH01144: No protocol handler was valid for the URL /subdir/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule., referer: http://localhost/
So after searching the internet, I have activated these modules:
LoadModule headers_module modules/mod_headers.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_express_module modules/mod_proxy_express.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_html_module modules/mod_proxy_html.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule rewrite_module modules/mod_rewrite.so
(I know that I don't need all of them but I just activated them to be sure I am not missing one)
But this error still appears and clients get a HTTP 500.
How can I fix this?
This can happen if you don't have mod_proxy_http enabled
sudo a2enmod proxy_http
For me to get my https based load balancer working, i had to enable the following:
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
For my Apache2.4 + php5-fpm installation to start working, I needed to activate the following Apache modules:
sudo a2enmod proxy
sudo a2enmod proxy_fcgi
No need for proxy_http, and this is what sends all .php files straight to php5-fpm:
<FilesMatch \.php$>
SetHandler "proxy:unix:/var/run/php5-fpm.sock|fcgi://localhost"
</FilesMatch>
In my case, I needed proxy_ajp module.
a2enmod proxy proxy_http proxy_ajp
This was happening for me in my Apache/2.4.18 (Ubuntu) setup. In my case, the error I was seeing was:
... AH01144: No protocol handler was valid for the URL /~socket.io/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
The configuration related to this was:
ProxyPass /~socket.io/ ws://127.0.0.1:8090/~socket.io/
ProxyPassReverse /~socket.io/ ws://127.0.0.1:8090/~socket.io/
"No protocol handler was valid for the URL /~socket.io/" meant that Apache could not handle the request being sent to "ws://127.0.0.1:8090/~socket.io/"
I had proxy_http loaded, but also needed proxy_wstunnel. Once that was enabled all was good.
To clarify for future reference, a2enmod, as is suggested in several answers above, is for Debian/Ubuntu. Red Hat does not use this to enable Apache modules - instead it uses LoadModule statements in httpd.conf.
More here:
https://serverfault.com/questions/56394/how-do-i-enable-apache-modules-from-the-command-line-in-redhat
The resolution/correct answer is in the comments on the OP:
I think you need mod_ssl and SSLProxyEngine with ProxyPass – Deadooshka May 29 '14 at 11:35
#Deadooshka Yes, this is working. If you post this as an answer, I can accept it – das_j May 29 '14 at 12:04
I am posting an answer here, since I had the same error message for a different reason.
This error message can happen, for example, if you are using apache httpd to proxy requests from a source on protocol A to target on protocol B.
Here is the example of my situation:
AH01144: No protocol handler was valid for the URL /sockjs-node/info
(scheme 'ws').
In the case above, what was happening was simply the following.
I had enabled mod proxy to proxy websocket requests to nodejs based on path /sockjs-node.
The problem is that node does not use the path /sockjs-node for websocket requests exclusively. It also uses this path for hosting REST entrypoints that deliver information about websockets.
In this manner, when the application would try to open http://localhost:7001/sockjs-node/info, apache httpd would be trying to route the rest call from HTTP protocol to to a Webscoket endpoint call. Node did not accept this.
This lead to the exception above.
So be mindful that even if you enable the right modules, if you try to do the wrong forwarding, this will end with apache httpd informing you that the protocol you tried to use on the target server is not valid.
In my case, all modules were correctly set up (https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension is a good starter) & I had the redirection working for a base url, let's say /mysite/
but I got the errors for any child ULR, let's say /mysite/login/
http://reverse-proxy.dns.com/mysite/ was properly redirected to the remote servers while http://reverse-proxy.dns.com/mysite/login/ failed at the Apache2 reverse proxying with OP's error message.
The issue was the ending / character in the proxypass directive "/mysite/". Working configuration for child URL is :
<Proxy balancer://mysite_cluster>
BalancerMember http://192.x.x.10:8080/mysite
BalancerMember http://192.x.x.11:8080/mysite
</Proxy>
<VirtualHost *:80>
[...]
ProxyRequests Off
ProxyPreserveHost On
ProxyPass "/mysite" "balancer://mysite_cluster"
ProxyPassReverse "/mysite" "balancer://mysite_cluster"
</VirtualHost>
Trailing / truly are tricky.
I tried to get an uwsgi:// working, but somehow the manual thought it was clear to me that I actually needed mod_proxy_uwsgi. It was not. Here is how you do it: How to compile mod_proxy_uwsgi or mod_uwsgi?
For me all above-mentioned answers was enabled on xampp still not working. Enabling below module made virtual host work again
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so