Apache2 mod_headers not working

Description of the question: I want to install my site "Access-Control-Allow-Origin", so I installed it in the apache configuration (almost anywhere), but it does not work. I also set other headers for testing, but it still doesn't work.

Apache version: 2.2.22

Apache Modules: http://www.anwcl.com/test/show_modules.php

My destination URL:

http://www.anwcl.com/test/test_only_div.html 

And it is associated with my local file:

 e:\wamp\www\test\test_only_div.html 

And here are my apache configurations:

E: \ WAMP \ Bin \ Apache \ apache2.2.22 \ conf \ httpd.conf

 ... LoadModule headers_module modules/mod_headers.so ... Include conf/extra/httpd-vhosts.conf ... 

E: \ WAMP \ Bin \ Apache \ apache2.2.22 \ conf \ additional \ HTTPd-vhosts.conf

 NameVirtualHost *:80 <VirtualHost *:80> Header add Access-Control-Allow-Origin "*" Header echo ^TS Header add MyHeader "Hello Joe. It took %D microseconds for Apache to serve this request." ServerAdmin xxx@gmail.com DocumentRoot "E:/wamp/www/" ServerName www.anwcl.com ErrorLog "logs/xxx.log" CustomLog "logs/xxx.log" common <Directory "E:/wamp/www/"> Header add Access-Control-Allow-Origin "*" Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> 

E: \ WAMP \ WWW \ .htaccess

 Header add Access-Control-Allow-Origin "*" Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS" 

E: \ WAMP \ WWW \ test \ .htaccess

 Header add Access-Control-Allow-Origin "*" Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type" Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS" 

And here Wireshark closes, there are no expected headers:

 http://www.anwcl.com/question/apache-mod-headers-not-working.jpg http://www.anwcl.com/question/apache-mod-headers-not-working-304.jpg 
+8
apache mod-headers
source share
4 answers

Check the output of php_info() to see if mod_headers is loaded from your apache web server.

0
source share

Perhaps a change has occurred and you do not see the changes in your browser. This is especially true if you are serving static files, such as images that you are trying to change headers.

You can even turn off cache when viewing a page with the Javascript console open and still don't see the changes taking effect.

What you want to find is the response code. If it is 304, the server acknowledged that your browser already has a valid representation of the requested file and will serve this file. If this happens, you won’t see the headers you added after the browser loaded this page.

To make sure this is the case, change the URL to http://myexample.com/myimage.jpg?t=1 or any other random request parameter and see if this works.

0
source share

I also ran into this problem and fixed it when I realized that /etc/apache2/sites-enabled/000-default.conf wrong virtual host in my configuration file found here: /etc/apache2/sites-enabled/000-default.conf .

I changed the default VirtualHost configuration when I used another with a different port.

 <VirtualHost *:6000> Header set Access-Control-Allow-Origin "*" </VirtualHost> 

I also ran into the error described by Dylan Maxi and circumvented it by disabling the cache in the browser inspector: Disabling cache in Chromium based browser Here is also a link to a site that I found useful: https://enable-cors.org/server_apache.html

0
source share

In my case, adding the Header set "key" "value" did not work. I had to use RequestHeader set "key" "value" for ProxyPass to send the header.

 <VirtualHost *:443> ServerName myserver.com ServerAlias www.myserver.com ProxyRequests Off ProxyPreserveHost On ProxyPass / http://127.0.0.1:8081/ ProxyPassReverse / http://127.0.0.1:8081/ RequestHeader set "X-Forwarded-Proto" "https" # # Setup SSL # # SSLProxyEngine on SSLEngine on SSLCertificateFile location-to-certificate.crt SSLCertificateKeyFile location-to-private.key SSLCertificateChainFile location-to-ca_bundle.crt </VirtualHost> 
0
source share

All Articles