Top Nav

Archive | Apache

Disable Basic Auth For Virtual Path On Plesk

In a recent case we needed to allow request to a particular virtual URL path on a site that was password protected with HTTP Basic Auth. The site was hosted on a Linux server with Plesk, nginx and Apache.  Typically this problem is solved by adding a “Satisfy Any” to the .htaccess in the directory that you want to remove authentication. But this does not work if the path is virtual instead of a physical directory path. Additionally we needed to allow access for a list of IP addresses. We tried an number of different solutions and ended up with the following:

Step 1 – The HTTP Basic Auth and IP access controls are configured in the .htaccess file like this:

Step 2 – In Plesk under:

Add the following block:

where “/excluded/path” is the virtual URL to be allowed access and “x.x.x.x” is the IP address assigned to the site.

When a request comes is received, nginx looks for the path and adds the AUTH_OVERRIDE header. Then the request is passed to Apache which processes the .htaccess file. The AUTH_OVERRIDE header is converted to an “AUTH_REQUEST” environment variable and allow without authentication by the “allow from env=” rule.

There may be better ways to accomplish this solution but this is one that we successfully implemented.

 

 

0

Mixing Basic Auth And IP Access Controls

In some cases you might want to require HTTP Basic authentication to a site but allow specific IP addresses to skip the username/password. For Apache this can be configured with:

For nginx the configuration is:

 

 

 

0

Turn off Keep-Alive for directory

Recently had a problem where Chrome browsers were not fully downloading a large PDF document. The first few 100KB would download but then the document would stop loading.

After some debugging we concluded that Keep-Alive in Apache was creating the problem. We didn’t want to disable KeepAlive for the entire server so instead we added this line to the .htaccess file containing the PDF files:

 

 

0

Enable Compression On Plesk With Nginx

To enable compression on a Plesk server with Nginx handling static content, had to add the following to .htaccess:

This configuration is explained here: https://www.a2hosting.com/kb/developer-corner/apache-web-server/data-compression-using-the-mod-deflate-module

And then in Plesk under:

Subscriptions -> acme.com -> Websites & Domains -> Web Server Settings -> Additional nginx directives

added the following:

The Nginx configuration is explained here: http://www.nginxtips.com/how-to-configure-nginx-gzip-compression/

2

Redirect With Query String

Let’s say you have URL like this:

http://acme.com/my-old-url

that you want to redirect to a new url:

http://acme.com/new-url

This is easily accomplished with a rewrite rule:

But what if the source URL has a url parameter like:

http://acme.com/my-old-url?id=27

In this case we need to use  RewriteCond to match the url parameter:

Notice the question mark (?) at the end of “/new-url?”. This causes the query string to be discarded. If the question mark is not included then the redirect will go to:

http://acme.com/new-url?id=27

If you want to keep the query string then you can explicitly add it with the QSA option like:

Also in Apache 2.4 and latter the QSD option can be used to exclude the query string with the same effect at the trailing question mark:

 

 

0