Header Expires not working - header

In httpd.conf the last lines are:
ExpiresActive On
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 3 days"
</FilesMatch>
When I run YSlow it says all my CSS files (and others) do not have expiration set. The CSS files are in subdirectories but I believe "\." should match all files regardless of subdirectory.
Apache is set up for virtual hosts, but the above directives are outside of vhosts section at the very bottom of httpd.conf.
There is a directive for LoadModule expires_module modules/mod_expires.so in the .conf file.
The site is on AWS running AWS Linux and Apache2. I restarted apache before checking if it worked.

In answer to your question, this works for me in my httpd.conf:
LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so
ExpiresActive On
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 3 days"
</filesMatch>
Here are a few things to try:
1) Make sure mod_expires.so is where you think it is. You can see what modules are being included by using this in your terminal: apache2 -M.
2) Make sure your directives apply to the files you're interested in (i.e. not getting overwritten by a .htaccess file somewhere farther down the line)
3) Make sure the LoadModule directive is in your httpd.conf file
4) In your FilesMatch regex, you should escape the dot with a backslash otherwise you're matching any character. Not a big issue, but you'd end up applying the rule to non-static pages like "site.com/politico" (note the ico ending) for example.

Related

Cgi/perl scripts display as code in Monterey

These scripts worked fine prior to upgrading to Monterey!
I have followed the tutorial from “etresoft” regarding editing the httpd.conf file and restarting Apache, but when executed the Perl script (code) displays in Safari. The scripts live in my Sites directory, and execute properly when run from there.
There are a suite of cgi/perl scripts that function to manage and present a family budget.
The first script opens a data file that contains various accounts: expenses (like groceries, utilities, etc.) and incomes. The script presents an HTML file with a large table, each line in the table documents an account, how much is due, and when. The script allows you to edit the various values. From this table page it is possible to call another script which will present those accounts due for the month and calculate the total amounts owed and the total incomes and the difference.
These are the edits made to /etc/apache2/httpd.conf:
Enabled the php and perl:
LoadModule php_modul/usr/local/opt/php#8.0/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
LoadModule perl_module libexec/apache2/mod_perl.so
Uncommented the LoadModule for userdir_module:
LoadModule userdir_module libexec/apache2/mod_userdir.so
Uncommented the Include line for httpd-userdir.conf:
User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf
Saved the httpd.conf file.
This is the edit made to /etc/apache2/extra/httpd-userdir.conf:
Uncommented the Include line for *.conf
Include /private/etc/apache2/users/*.conf
I edited /etc/apache2/users/<your short user name>.conf. It now looks like this:
<Directory "/Users/rjklaus/Sites/">
AddLanguage en .en
AddHandler perl-script .pl
Options Indexes MultiViews FollowSymLinks Includes ExecCGI
DirectoryIndex index.html index.cgi index.php
AllowOverride None
Require host localhost
</Directory>
From a “Terminal” window I ran the following command:
chmod +a "_www allow execute" ~
I ran apachectl configtest and received a “Syntax OK”.
I next entered http://localhost/ into the Safari address bar. I did NOT see the “It works!” that I was told to expect. Instead I got:
/Users/rjklaus/Ray's%20Stuff/HTML%20Budget/test.pl
“HTML Budget” is a file (not a directory) in a subdirectory of “Ray’s Stuff”. The text string “test.pl” is not in that file. Test.pl is a short perl script in my Sites directory.
I am running perl v5.30.3 from /usr/bin/perl.
There are three versions of Apache2 located in /Users/Shared/ subdirectories labeled:
Previously Relocated Items,
Previously Relocated Items 1, and
Previously Relocated Items 2.
just to be sure, the cgi_module is enabled?
<IfModule !mpm_prefork_module>
LoadModule cgid_module lib/httpd/modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module lib/httpd/modules/mod_cgi.so
</IfModule>

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

apache2 and php5-fpm, how to correctly process *.phps files?

I've setup my server using apache2 and php5-fpm, pretty much like in this guide:
http://www.versatilewebsolutions.com/blog/2012/11/installing-apache-2-with-php-fastcgi-on-ubuntu-12-10.html
The only question left is, how can I configure it to correctly process the *.phps files?
I want to show the highlighted code of them.
There are guides for nginx and php-fpm ( https://blog.kamalnasser.net/post/highlighting-phps-files-in-nginx/ ), but what should we do with apache2 ?
Caveats: Ubuntu 14.10, Apache/2.4.10
In the file /etc/apache2/mods-available/php5.conf:
<FilesMatch ".+\.phps$">
SetHandler application/x-httpd-php-source
# Deny access to raw php sources by default
# To re-enable it's recommended to enable access to the files
# only in specific virtual host or directory
Order Deny,Allow
Deny from all
</FilesMatch>
Add a with "Allow from all" (or something more appropriate to your paranoia-level) to you host config, and you'll be all set.
My config:
<Directory /my/very/long/and/winding/server/path/public_html/phpsource/>
<FilesMatch ".+\.phps$">
Order Deny,Allow
Allow from all
</FilesMatch>
</Directory>
Php Source files in other directories get denied, the ones in that directory gets displayed. It works like a charm...
This should do it:
AddType application/x-httpd-php-source .phps
Add it to your apache config file. There should be a similar line like this:
AddType application/x-httpd-php .php
So just add it below.

ExpiresDefault on dynamic url?

I have different types of dynamic urls like
/dynamic/image/day/blah/blah/blah.jpg
/dynamic/image/week/blah/blah/blah.png
/dynamic/image/month/blah/blah/blah.gif
this urls are not actual filesystem paths but served by a php script ..
IN httpd.conf :
whey I try with the following configuration :
ExpiresActive On
ExpiredDefault A0
<LocationMatch */image/day/*>
ExpiresDefault A86400
</LocationMatch>
<LocationMatch */image/week/*>
ExpiresDefault A604800
</LocationMatch>
It applies last one 'A604800'(after week) expiry header to both type of files .. means even for /day/ type of urls the last ExpiresDefault is overriding to all the above ExpiresDefault .
I have also tried putting FilesMatch inside LocationMatch like this :
<LocationMatch */image/week/*>
<FilesMatch "\.(jpg|jpeg|png)">
ExpiresDefault A604800
</FilesMatch>
</LocationMatch>
But now not a single directing inside FilesMatch is executing meanse Expires header is not set ..
I have also tried using Header set ,, but looks like it doesn't follow Locationmatch condition but just last Header Set whould apply to all ..
Those are dynamic url , not actual directories , so I can't use different htaccess for different day,week etc ..
Any Solution ..?

configure apache run run php in html pages

How can I make apache parse php code inside my html pages? I don't wanna use .htaccess. I've added:
AddType application/x-httpd-php .html
AddType application/x-httpd-php .php
in my vhost file for one of the websites but it won't work.
Did you build your Apache binary with PHP? Or if you built a SO, reference it in the Apache config (e.g.: LoadModule php5_module modules/libphp5.so)?
When using .html for PHP, ensure 'AddType text/html .html' is removed, so it doesn't conflict with the x-httpd-php reference.
FYI -- you can create one entry 'AddType application/x-httpd-php .html .php'
I have the same problem in the latest versions (Debian 10 , Apache 2.4.25, PHP 7.0.33)
My solution is edit the php.config file, to find it I put:
find -iname php*.conf
...and in my debian instalation I found it in:
/etc/apache2/mods-available/php7.0.conf
Then, I introduce those lines at begining:
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
And it work for me.