Apache proxy gzip - apache

I am using Apache 2.4 as a proxy server. All requests that have myapp are being redirected to tomcat that serves files. I am using mod_proxy.so(proxy) and mod_deflate.so (gzip). In my httpd.config (Apache config) this is what I have:
ProxyPass /myapp/ http://myserver:58080/myapp/
<Location /fusebox/>
ProxyPassReverse /myapp/
RequestHeader unset Accept-Encoding
#SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/javascript application/x-javascript application/x-httpd-php
</Location>
Do you have any suggestions why this is not working?
Thank you

Sorry about the short answer, but I'm just passing by in a hurry.
Your proxypass-directive is likely working og Apache is likely serving out content from your Tomcat (if your Tomcat is healthy).
Your proxypassreverse-directive, requestheader and outputfilter are unlikely to be doing anything since they are contained in a location-directive not related to your proxypass. Loose the location-tags and things are going to happen.
Kind regards,
Helge

Related

Redirect all HTTP/HTTPS requests Apache to a specific website and then back

What I want to do (ALL THIS IS PERFORMED ON ONLY ONE SERVER);
(I'm working with example.com for not making any advertisement).
Redirect all incoming HTTP/HTTPS requests (Port 80 and 443) to a specific website, for example, filter.example.com. There I've made my own mechanism to filter malicious requests. After that, the requests should get back to the requested website.
My problem is, that every request is getting redirected back to the filter, so there's an endless loop.
Do you know any solution to that or maybe an alternative (Nginx)?
Here's the problem showed by the packet flow;
"User - Request = https://example.com" -> "Apache redirects it to = https://filter.example.com" -> "After getting filtered = https://example.com" -> "Apache is redirecting it back again."
I really hope you understand my problem.
Thank you.
EDIT:
This are my settings for the filter.example.com ServerName;
<VirtualHost *:80>
ServerName filter.example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
ServerName filter.example.com
RewriteEngine On
DocumentRoot /var/www/filter/
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/filter.example.com/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/filter.example.com/chain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/filter.example.com/privkey.pem
ErrorDocument 404 /error404.html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</VirtualHost>
And here for my "real" website;
<VirtualHost *:80>
ServerName example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
RewriteEngine On
DocumentRoot /var/www/html/
SSLEngine On
SSLCertificateFile /etc/letsencrypt/live/example.com/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
ErrorDocument 404 /error404.html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</VirtualHost>
So, David wrote;
You will really end up in a redirect loop because the request 1 to www.example.com will redirect to filter.example.com and again to www.example.com endlessly.
To avoid this add a cookie/header to the incoming request from www.example.com in filter.example.com(of course, after completing the filter process) something like Filter: true, so you know this is already a filtered request and doesn't need to go to filter.example.com.
server {
server_name filter.example.com;
//logic to filter
add_header 'passed_filter' 'true';
}
If you redirect logic to add a check to verify if header Filter: true exists, if not redirect to filter.example.com, if yes - skip redirect and follow the normal execution procedure.
//If the header is not set, then we understand that this request should be redirected to filter.example.com
if($sent_passed_filter ~= 'true') {
//logic to redirect to filter
}
Is that Nginx, because I'm using Apache. Is there also a solution like that but for Apache?
You will really end up in a redirect loop, because the request 1 to www.example.com will redirect to filter.example.com and again to www.example.com endlessly.
To avoid this add a cookie/header to the incoming request from www.example.com in filter.example.com(of course, after completing the filter process) something like Filter: true, so you know this is already a filtered request and doesnt needs to go to filter.example.com.
server {
server_name filter.example.com;
//logic to filter
add_header 'passed_filter' 'true';
}
In you redirect logic add a check to verify if header Filter: true exists, if not redirect to filter.example.com, if yes - skip redirect and follow the normal execution procedure.
//If the header is not set, then we understand that this request should
be redirected to filter.example.com
if($sent_passed_filter ~= 'true') {
//logic to redirect to filter
}

apache httpd substitute wont work

I configured apache httpd to apply substitute.
For my eyes it is exactly what the doc says.
However it does simply nothing.
What is wrong with it?
<VirtualHost domain:443>
SSLEngine on
....
ProxyPass /cms/ http://domain2/
ProxyPassReverse /cms/ http://domain2/
Substitute "s|div|DIV|ni"
</VirtualHost>
(Apache 2.4.16 on Centos)
Meanwhile I figured out how to make it work
<VirtualHost domain:443>
SSLEngine on
....
# In some case the following line is neccessary
RequestHeader unset Accept-Encoding
<Location /cms >
ProxyPass http://domain2/
ProxyPassReverse http://domain2/
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|div|DIV|ni"
</Location>
</VirtualHost>
I hope this helps others to overcome similar problems.
(We use it to exchange urls from a proxied source,
after hard work apache httpd is a great tool ;-))
This worked for me: AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html
see https://serverfault.com/questions/843905/apache-mod-substitute-works-in-curl-but-not-on-browser?newreg=c6eab8403f83476096a3d49dd64edeeb
Thank you, stefan for finding the solution, I was stuck with the same issue.
For what it's worth, in my case, the back-end server is providing html but also some javascript, graphql end-point and other APIs, which required to also add other mime-types, and the final config would look like this:
<VirtualHost domain:443>
SSLEngine on
....
RequestHeader unset Accept-Encoding
<Location /cms >
ProxyPass http://domain2/
ProxyPassReverse http://domain2/
AddOutputFilterByType SUBSTITUTE text/html text/xml text/javascript application/json
Substitute "s|div|DIV|ni"
</Location>
</VirtualHost>

How to enable GZip compression in Zend Server CE

I work with Falsh buider and httpserver.
To accelerate result display, I'd like to activate compression on Zend Server.
I create .htaccess on /usr/local/zend/apache2/htdocs/, like this:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# Insert filter on selected content types only
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
I restart zend server, but compression seems to be desable.
Indeed on log, file size is the with compression and without.
So can you help me to solve that.
Thanks
You may need to add
AddOutputFilterByType DEFLATE application/x-amf
since you may be indicating that you are using Flash remoting
According your comment, I modify httpd.conf like that:
LoadModule deflate_module modules/mod_deflate.so
<Location />
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/xml application/xml application/x-amf
</IfModule>
</Location>
Now delate_module is loaded.
But when I launch httpservice from flex with e4X resultformat, result file has same size that without compression, Why?
Thanks for helping

Enable mod_deflate

I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code in my .htaccess file:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
<FilesMatch "\\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
It did not compress any of my files when I tested my site in firebug. What am I doing wrong?
As this'll be moved to SF soon, Shouldn't it be:
<FilesMatch "\.(js|css|html|htm|php|xml)$">
Otherwise the regex becomes \.js, for example (because you've escaped the '\').
SetOutputFilter DEFLATE
I used this and it worked. It was an internet history problem. My yahoo Yslow was saving the results from the first check so when I modified the htaccess the difference did not show up.

Strange CSS/Apache problem

I have been trying to install ReviewBoard and all looks like it has gone well, in as much as I can access the site and functionality
However, I have strangeness where no style sheet appears to be applied for some reason.
I suspect it may be a permissions issue on a folder that it can't access or some Apache setup error I have made.
Is there any Apache configuration that could have caused this?
Has anyone experienced any similar problems not just for ReviewBoard?
Further info: It looks like Apache is receiving the request for the Stylesheets
[20/May/2009:10:00:35 +0100] "GET /reviewboard/media/rb/css/common.css?1242747706 HTTP/1.1" 404 2512
[20/May/2009:10:00:35 +0100] "GET /reviewboard/media/rb/css/ie_hacks.css?1242747706 HTTP/1.1" 404 2514
[20/May/2009:10:00:36 +0100] "GET /reviewboard/media/rb/js/csshover2.htc?1242747706 HTTP/1.1" 404 2514
[20/May/2009:10:00:36 +0100] "GET /reviewboard/media/rb/js/pngfix.htc?1242747706 HTTP/1.1" 404 2511
EDIT: Looking at the access logs the GET for the CSS is actually 404-ing as the path should be reviewboard/htdocs/media/rb/css/* (although there is an alias in the HTTP.conf that I assumed dealt with this.
EDIT: The .htaccess file contains
<IfModule mod_expires.c>
<FilesMatch "\.(jpg|gif|png|css|js|htc)">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
EDIT:
The httpd.conf sections looks like this
<VirtualHost *:8080>
ServerName FASKALLYRB
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/reviewboard/htdocs"
# Error handlers
ErrorDocument 500 /errordocs/500.html
ErrorDocument 404 /errordocs/500.html
# Serve django pages
<Location "/">
PythonPath "['C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/reviewboard/conf'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE reviewboard.settings
SetEnv PYTHON_EGG_CACHE "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/reviewboard/tmp/egg_cache"
SetHandler mod_python
PythonHandler django.core.handlers.modpython
PythonAutoReload Off
PythonDebug Off
# Used to run multiple mod_python sites in the same apache
PythonInterpreter reviewboard_reviewboard
</Location>
# Serve static media without running it through mod_python
# (overrides the above)
<Location "reviewboard/media">
SetHandler None
</Location>
<Location "reviewboard/errordocs">
SetHandler None
</Location>
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/reviewboard/htdocs">
AllowOverride All
</Directory>
# Alias static media requests to filesystem
Alias reviewboard/media "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/reviewboard/htdocs/media"
Alias reviewboard/errordocs "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/reviewboard/htdocs/errordocs"
</VirtualHost>
The URL for Location and Alias directives can't be relative and needs a leading slash. Thus you should be using '/reviewboard/.......'.
FWIW, the PythonInterpreter directive isn't used for what your comment against it seems to indicate you think it does.
# Used to run multiple mod_python sites in the same apache
PythonInterpreter reviewboard_reviewboard
The application is always run within same Apache instance. What PythonInterpreter does is allow you control which Python sub interpreter within each Apache server child process it runs. It is actually redundant in your case, as the same sub interpreter is by default used for all mod_python hosted applications under the same VirtualHost. Note that there will still be multiple instances of the application, on in each of the Apache server child processes.
You could make a symlink in reviewboard called 'media' that points at htdocs/media perhaps.
Alternatively:
move htdocs/media to ..
or go into the reviewboard code and tweak the url generating code
or if you have mod_rewrite installed you could redirect requests to the right place