In Magento CE, I'd like to install an add-on to Extendware Page Cache called Lightening Cache.
It requires editing the Apache configuration inside the virtual host definition for the site, by adding:
RewriteEngine On
RewriteMap ewpchash prg:/home/.../shell/extendware/ewpagecache/apache/md5.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !\.(js|css|png|jpg|jpeg|ico|gif)$ [NC]
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteCond ${ewpchash:%{HTTPS};~;%{HTTP_HOST};~;%{REQUEST_URI};~;%{QUERY_STRING};~;%{HTTP:Cookie};~;%{SCRIPT_FILENAME};~;%{REMOTE_ADDR};~;%{HTTP_USER_AGENT}} -f
RewriteRule ^(.*)$ ${ewpchash:%{HTTPS};~;%{HTTP_HOST};~;%{REQUEST_URI};~;%{QUERY_STRING};~;%{HTTP:Cookie};~;%{SCRIPT_FILENAME};~;%{REMOTE_ADDR};~;%{HTTP_USER_AGENT}} [NC,L]
<FilesMatch "\.(html)$">
Header unset Cache-Control
Header unset Expires
Header append Expires "Thu, 19 Nov 1981 08:52:00 GMT"
Header append Cache-Control "must-revalidate"
</FilesMatch>
I have added this to the bottom of /etc/apache2/sites-enabled/site.conf.
When I run the command apachectl graceful, I receive the error:
AH00526: Syntax error on line 53 of
/etc/apache2/sites-enabled/site.conf: Invalid command 'Header',
perhaps misspelled or defined by a module not included in the server
configuration Action 'graceful' failed. The Apache error log may have
more information.
Site is running Apache 2.4
Have I done something wrong?
In order to use Header directive in apache you have to load mod_header module.
You can test if module is loaded or not by :-
apache2ctl -M | grep headers_module
find / -name mod_headers.so
If it is loaded you will see something like :-
headers_module (shared)
/usr/lib/apache2/modules/mod_headers.so
If you see no output of find command than load that module directly in your apache conf file. Just append below line :-
LoadModule headers_module modules/mod_headers.so
Note :- mod_header is available as base module in apache. So you don't need to install it explicitly.
Issue following command :-
a2enmod headers
Restart web service
apache2ctl restart
If someone is experiencing this error on a dockerized apache, the solution was only add this to my Dockerfile
RUN a2enmod headers
This was the error log:
[Fri Oct 21 17:39:55.384761 2022] [core:alert] [pid 19] [client 172.17.0.1:57480]
/var/www/html/page1/.htaccess:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
And the error:
And the .htaccess:
Header add X-Custom "Custom Value"
Solution
Here my complete Dockerfile:
FROM php:8.0-apache
RUN a2enmod rewrite
RUN a2enmod headers
COPY src/ /var/www/html
EXPOSE 80
After the fix:
Related
I have added a new domain to Amazon linux server running apache
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain
ErrorDocument 404 /index.html
ErrorLog /var/log/mydomain.com-error_log
CustomLog /var/log/mydomain.com-access_log common
<Directory /var/www/mydomain>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
Restarted the server
checked status
sudo systemctl restart httpd active (running) 1 min
But for whatever reason the default apache index.html is served
Directory exists for the new domain , index.html is there chmod 644 done
Error log for the new domain is empty.
Access log and error lod are empty
-rw-r--r--. 1 root root 0 Dec 21 15:26 mydomain.com-access_log
-rw-r--r--. 1 root root 0 Dec 21 09:50 mydomain.com-error_log
tail of host error_log is normal
AH00489: Apache/2.4.37 (Red Hat Enterprise Linux) OpenSSL/1.1.1c configured -- resuming normal operations
[Mon Dec 21 15:02:24.161922 2020] [core:notice] [pid 73594:tid 140519198484800]
AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
I feel a permissions/cert problem. Or one more thing letsencrypt crt has been installed for the new domain probably successfully
[ec2-user#ip-xx-xx-xx-xx ~]$ wget mywwwdomain.com
--2020-12-21 15:57:26-- http://mywwwdomain.com/
Resolving mywwwdomain.com (mywwwdomain.com)... 55.55.55.55
Connecting to mywwwdomain.com (mywwwdomain.com)|55.55.55.55|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://mywwwdomain.com/ [following]
--2020-12-21 15:57:26-- https://mywwwdomain.com/
Connecting to mywwwdomain.com (mywwwdomain.com)|55.55.55.55|:443... connected.
ERROR: The certificate of ‘mywwwdomain.com’ is not trusted.
ERROR: The certificate of ‘mywwwdomain.com’ hasn't got a known issuer.
The certificate's owner does not match hostname ‘mywwwdomain.com’
[ec2-user#ip-xx-xx-xx-xx ~]$
55.55.55.55 - my IP address
How to debug further and fix this?
If you added a new domain in a new file, make sure the new file is properly included in the main httpd config file.
You can get a list of the VHs apache is serving issuing the following command:
# apache2ctl -S (On Debian/Ubuntu), # apachectl -S (On CentOS/RHEL) or
# httpd -S.
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.
Good day
Im trying to install a GamePanel with PHP called Swiftpanel on my VPS Centos7 64bit
i installed LAMP on my vps and html files work perfectly.
But my gamepanel doesnt work
and the gamepanel is located at:
http://51.255.199.40/gpanel/
as you can see when i try reaching my gpanel it gives me the SERVER ERROR 500
i looked at my apache error logs and this is what i get:
[Fri Mar 04 15:53:53.533162 2016] [autoindex:error] [pid 18753] [client 46.99.59.98:51034] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive
Here is my httpd.conf and php.conf:
http://pastebin.com/HJfH3gWQ
I need some help fixing this, im a begginer in coding.
With respect
Benjamin Selmani
In httpd.conf, try changing the line:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
to
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
and restart Apache.
OK, edit your httpd.conf file and change the following line:
Options Indexes FollowSymLinks
to:
Options +Indexes +FollowSymLinks
then restart your Apache server. If this doesn't work, it's likely we are editing the wrong httpd.conf file. You'd be surprised how many you might find on your computer including all the conf files in sub directories (look at the last line of your httpd.conf file). Somewhere there is probably a line that looks like this:
Options -Indexes
Which is the explicit cause of the problem. But try my earlier suggestion first.
i searched sth about this a lot but solutions doesnt help so much.I tried to upgrade redmine to 2.6.5 on my FreeBSD but i have 403 error.
apache error log:
[autoindex:error] AH01276: Cannot serve directory
/usr/local/www/redmine/public/: No matching DirectoryIndex (none)
found, and server-generated directory index forbidden by Options
directive
my httpd conf:
<VirtualHost example.com:80>
DocumentRoot "/usr/local/www/redmine/public"
ServerName example.com
FastCgiServer /usr/local/www/redmine/public/dispatch.fcgi -idle-timeout 120 -initial-env RAILS_ENV=production -initial-env PATH=/usr/local/bin -processes 2
<Directory "/usr/local/www/redmine/public">
AddHandler fastcgi-script fcgi
Order allow,deny
Allow from all
AllowOverride all
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi
</Directory>
ErrorLog /logs/error.log
</Virtualhost>
i have to say: if i add +Indexes in Option i see files in my browser, so i guess premissions are good.
Anyone can give me any hint?
thanks in advance 4 your help
In my situation the problem was caused by a bug in the apache module ModAutoIndex. Disabling the module did the trick.
See https://serverfault.com/a/731859
Disabling the module auto index (which is the cause of the wrong behaviour, will prevent the error.
#LoadModule autoindex_module modules/mod_autoindex.so
Phusion will address the issue in the realase of Passenger 5.0.22 before Apache 2.5.0 will be released.
I suffered the same issue on my ArchLinux installation with Apache 2.4 and Redmine 2.6.5. Instead of fcgi I use the Phusion Passenger web application server but I always ended up on a 403 Forbidden page like you when accessing the server.
With the +Indexes option I also got the contents of the Redmine public directory on the browser.
When using webrick or passenger directly to host Redmine everything was fine. That's how you can verify your Redmine is not corrupted somehow. From the Redmine root directory run:
bundle exec ruby scripts/rails server -e production
Since I'm using RVM to manage ruby versions and gemsets on the system I can also tell you that the behavior is not related to ruby ( I tried every version from 1.8.x to 2.2.x without any change ).
In the end I substituted Apache with nginx 1.8.0 (stable release) and got Redmine back to work. So with passenger it's quite easy to get rolling. Just run
gem install passenger
so you get the passenger package. And then compile nginx with the passenger module using
passenger-install-nginx-module
You'll get an automated dialog that downloads nginx and compiles it with the appropriate config. By default it will be installed to /opt/nginx
On ArchLinux you would rather use the ABS to get the PKGBUILD and add the following to the configure part
--add-module=$(passenger-config --nginx-addon-dir) \
That way you also get the systemd unit-file to start and stop nginx.service
Last but not least here's the nginx config I use to run Redmine:
server {
listen 80;
server_name redmine.example;
root /usr/share/webapps/redmine-2.6.5/public;
passenger_base_uri /;
passenger_app_root /usr/share/webapps/redmine-2.6.5;
passenger_document_root /usr/share/webapps/redmine-2.6.5/public;
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-1.9.3-p551#redmine/wrappers/ruby;
}
Using another webserver may be a daunting step but it took me less than 2 hours to get Redmine up and running with nginx compared to nearly 2 days of wasted time to figure out why the heck Apache didn't serve the webapp any more.
What I have done:
Install apache 2.4 and php 5.4 from source.
apache config:
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
php config
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd\
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir\
--with-png-dir\
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2\
--with-apxs2=/usr/local/apache/bin/apxs
In the httpd.conf file, I enabled the mod_proxy.so and mod_proxy_fcgi.so and add the following config:
<IfModule proxy_module>
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/$1
</IfModule>
from phpinfo(), I see the Server API is FPM/FastCGI
My Problem:
I set the DirectoryIndex as below. I have index.html in the DirectoryRoot which is "/var/www". When I visit localhost, I am supposed to see the content of index.html. But it gave a 404 file not found.
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
When I switch the position of index.html and php in the above code. This time the html file is in front of php file. Then when I visit localhost, I can see the right content.
And I checked the apache error log. It says:
[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unkn own\n'
When there is only index.php file in the /var/www, and leaving the httpd.conf like
<IfModule dir_module> DirectoryIndex index.html index.php</IfModule>
Also got 404, visiting the localhost.
My Question:
How do I fix the above problem?
I did some research on the configuration of fastcgi. like this and this
They dont mention the mod_proxy_fcgi, but all refering this
"FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -host
127.0.0.1:9000"
So I am not sure if I am using the FastCgi the right way? Does this wrong way cause the above problem?
【P.S.】
Thank you regilero. I'm not using vhost and I had checked the error.log. It seems having something to do with php-fpm. The response page in the browser says "file not found", not "404", although the response code is 404. Here is what's in the error.log
[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unknown\n'
I try to forward all the requersts ended with ".php" to fcgi. But the error above looks like that when I request index.html, it is also forwarded to the fcgi, which fcgi cannot handle it.(This is my guess) For the config about this forwarding, please see the code above, or search this page for "fcgi://".
Here is my Directory config. I'm not sure if this is what you need.
DocumentRoot "/var/www"
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This is somewhat of a linked answer however it's one I share with many who come across the problem you are facing now and it seems to do the trick.
Checkout this GIST -> https://gist.github.com/diemuzi/3849349
There you will find all my working configurations for Apache and PHP-FPM. It seems like a better place to organize my configurations instead of pasting them here and confusing others. This link will not expire so no worries about that.
Perhaps also you can compare my working examples with what you have and find something missing that you currently are not using. Hope this helps!