-
How to compile and build Apache modules on Windows using Visual Studio
Posted on June 10th, 2011 2 comments
Print
Over the weekend, I had to do a new build of the mod_xsendfile module since I put a custom fix for the issue I was having. As it turns out, however, compiling Apache modules on Windows is not very straightforward at all (Linux, on the other hand, you just simply type apxs2 -cia some_apache_module.c).
After lots of Googling and trying different approaches, I finally got it to work by doing the following using Microsoft Visual Studio. Note that I only tried this on the mod_xsendfile module but I’m assuming this will work for building other Apache modules as well:
You can download Microsoft Visual Studio Express for free here if you don’t have VS (I used VS 2008 Pro): http://www.microsoft.com/express/Windows/
1. Download the Apache 2.2 Windows installer: http://httpd.apache.org/download.cgi
2. During the installation, select Custom setup type and make sure the Build Headers and Libraries option is marked to be installed.
3. If your module’s source contains a .vcproj file, simply open it up. If not, just create a new project in Visual Studio.
-
Apache 2.2: Partial results are valid but processing is incomplete, unable to stat file (X-Sendfile)
Posted on June 9th, 2011 5 comments
Print
Error Message:
(70008) Partial results are valid but processing is incomplete: xsendfile: unable to stat file: //server_name/folder/file
I deployed my code to our development box over the weekend which uses the X-Sendfile module for Apache to serve files but ran into this issue when I tried to download a file. The X-Sendfile module worked fine on my local machine. The only difference I could find was our development box was running Windows XP 64-bit and I’m running 32-bit (this is why it’s a good idea to try to have the machines in all your environments to be identical, VMs are great for this).
I couldn’t find a solution for my exact problem so I decided to check out the source code and searched for the error message “unable to stat file”:
/* stat (for etag/cache/content-length stuff) */ if ((rv = apr_file_info_get(&finfo, APR_FINFO_NORM, fd)) != APR_SUCCESS) { ap_log_rerror( APLOG_MARK, APLOG_ERR, rv, r, "xsendfile: unable to stat file: %s", translated ); apr_file_close(fd); ap_remove_output_filter(f); ap_die(HTTP_FORBIDDEN, r); return HTTP_FORBIDDEN; }It appears that the apr_file_info_get() function was not returning APR_SUCCESS on our development box for some reason. I did some research on that function and found an old article that mentions something about one of the arguments may be beyond the OS file system support and would always return APR_INCOMPLETE (http://dev.ariel-networks.com/apr/apr-tutorial/html/apr-tutorial-5.html).
I put a quick fix/hack to make it work in our environment by simply checking for both APR_SUCCESS and APR_INCOMPLETE and only throw the error when the status is neither of those.
I simply changed:
if ((rv = apr_file_info_get(&finfo, APR_FINFO_NORM, fd)) != APR_SUCCESS)
to
if ((rv = apr_file_info_get(&finfo, APR_FINFO_NORM, fd)) != APR_SUCCESS && (rv = apr_file_info_get(&finfo, APR_FINFO_NORM, fd)) != APR_INCOMPLETE)
I then did a compile/build on Windows (this is another story), redeployed the module, and it finally worked! I also checked the MD5 and SHA-1 hashes of a couple of files served through mod_xsendfile just to make sure it’s working properly and they matched the original hashes.
You can download the source and the .so file (if you trust me enough
) with the fix from here. -
Apache: Redirecting http to https using a .htaccess file
Posted on March 23rd, 2008 No comments
Print
To redirect http traffic to https in Apache, create a .htaccess file with the following content:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}Place the .htaccess file in your website directory and that should be it.
NOTE: The rewrite module in Apache must be enabled for this to work. To check whether it is enabled, open your httpd.conf and make sure the line below is not commented:
LoadModule rewrite_module modules/mod_rewrite.so
If you’re running Apache on Windows, you won’t be able to create a file with a filename that starts with “.” so you will have to tell Apache to look for another file. To do so, simply open your httpd.conf and change the line:
AccessFileName .htaccess
to
AccessFileName ht.acl .htaccess
Instead of naming the file .htaccess, name it ht.acl. Restart Apache and it should work.



Recent Comments