Enable mod_headers in Apache in Windows - apache

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.

Related

how to config apache in xampp for logging post request

I run xampp and host DVWA on it. but didn't log all of http request and post request.
how to change apache config file (httpd) to log full request?
thanks.
my apache config file is:
https://www.filemail.com/d/vvkrdbixuqiaujz
When you say full request I guess you mean body of requests here is the simplified guide
finally I fix it:
according to this post
first uncomment LoadModule dumpio_module modules/mod_dumpio.so and second added this lines to httpd.conf in xampp:
<IfModule dumpio_module>
DumpIOInput On
DumpIOOutput On
LogLevel warn dumpio:trace7
</IfModule>
and restart apache.
now if search in error.log find text in post body.

How to Enable CORS for Apache httpd server? (Step-By-Step Process)

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

Apache Proxy: No protocol handler was valid

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

Looking for "localhost" apache server that allows .htaccess

Is there some apache server software out there that can be installed on my Windows PC (for local development purposes) that also allows .htaccess for URL rewriting?
I'm currently using Xampp which does not seem to offer this functionality (although maybe I'm wrong about that).
Any advice would be much appreciated.
Thanks.
You will have to activate mod_rewrite in your apache config. Go to your xampp folder an you will find the httpd.conf file in apache/conf/. Open it an go to the line with:
#LoadModule rewrite_module modules/mod_rewrite.so
Change it to
LoadModule rewrite_module modules/mod_rewrite.so
Save the httpd.conf and restart your apache. Now mod_rewrite should work.
Xampp will do it, you'll need to enable mod_rewrite first.
open the directory you installed Xampp then open \apache\conf\httpd.conf in notepad and search for mod_rewrite.
Uncomment the line by removing the # from the beginning. By default mod_rewrite is disabled on a fresh install.
LoadModule rewrite_module modules/mod_rewrite.so
Restart Xamppp should take .htaccess rules now.
It's true that by default, Xampp on windows does not support URL rewriting.
However it's an pretty easy fix:
In your httpd.conf file, find the line that contains "mod_rewrite" and remove the # in front of it
Again in your httpd.conf file, find all occurrences of AllowOverride None and change it to AllowOverride All
Restart apache and you're done:)

How do you configure the Apache server which ships Mac OS X?

Mac OS X ships with apache pre-installed, but the files are in non-standard locations. This question is a place to collect information about where configuration files live, and how to tweak the apache installation to do things like serve php pages.
Apache Config file is: /private/etc/apache2/httpd.conf
Default DocumentRoot is: /Library/Webserver/Documents/
To enable PHP, at around line 114 (maybe) in the /private/etc/apache2/httpd.conf file is the following line:
#LoadModule php5_module libexec/apache2/libphp5.so
Remove the pound sign to uncomment the line so now it looks like this:
LoadModule php5_module libexec/apache2/libphp5.so
Restart Apache: System Preferences -> Sharing -> Un-check "Web Sharing" and re-check it.
OR
$ sudo apachectl restart
Running
$ httpd -V
will show you lots of useful server information, including where the httpd.conf file can be found.
To get SSI/includes (mod_include) to work I found I had to edit /private/etc/apache2/users/myusername.conf and change AllowOverride None to AllowOverride All.
Then add the following in a .htaccess file in the root of your site:
Options +Includes
AddType text/html .html
AddOutputFilter INCLUDES .html
httpd.conf is in /private/etc/apache2
Enable PHP by uncommenting line:
LoadModule php5_module libexec/apache2/libphp5.so
/etc/httpd/users contains user-specific configuration files which can be used to override the global configuration. For example, adding "AddHandler server-parsed html" to the <Directory> block in the /etc/httpd/users/*.conf file that corresponds to one user will enable mod_include parsing of HTML files for that particular user's $HOME/Sites directory, but nowhere else.