Compiling Lua with Visual Studio 2010

It’s not often I have to venture into the Microsoftland development environment, but when I do it always seems to take me a while to get used to their visual projects instead of good ‘ole Makefiles. I’ve been using Lua to extend my C and C++ apps a lot recently, so I suddenly found myself needing to include the Lua static library with a Visual Studio 2010 project.

There are already binary distributions out there, but I like to compile things myself, so I whipped up a Visual Studio 2010 project to compile the Lua static library (lua.lib) the command line interpreter (lua.exe) and the script compiler (luac.exe).

First things first. If you just want a zip file with those three binary files (the library is Visual Studio 2010 compatible), look no further:

If you want to build Lua 5.1.4 yourself (like me) just grab the most recent copy of the 5.1.4 source code from the Lua website. Next, grab these Visual Studio 2010 project files and solution file:

To use the project files, just unzip them into the root directory of your Lua source files (where the README, INSTALL, and COPYRIGHT files are). Then, load up lua-vs2010.sln in Visual Studio 2010. You should see three projects. The first, lualib will build the static library under lib/lua.lib. The second and third, lua and luac will build the Lua interpreter and compiler under bin/lua.exe and bin/luac.exe.

Enjoy!

SSL detection by PHP scripts run through FastCGI on nginx

How’s that title for acronym soup?

I ran across this issue when playing around with nginx. I was trying to set up phpMyAdmin for SQL administration, but ran into a rather peculiar issue. To explain the problem, let me give you some context.

I’m running nginx only on port 443, using SSL for everything. As I’m going through the setup for phpMyAdmin, imagine my surprise when it alerts me that I’m not using an SSL connection. In fact, it’s impossible for me not to use SSL, because there’s no regular HTTP server running on port 80. I continued with the setup anyway, checking the ForceSSL option which requires all phpMyAdmin requests to be done over SSL. When I finished installing it and tried to log in, I got a Firefox error that it was stuck in a redirect loop.

Much Google searching later, I still couldn’t find the problem. This was when I remembered that PHP is configured differently on nginx that is typically done with Apache. With Apache, many people use the mod_php module that compiles PHP support directly into the server. With nginx, you generally process PHP requests using FastCGI.

I wondered if perhaps the fact that the connection was taking place over SSL wasn’t being passed through to the FastCGI process. If that was the case, the phpMyAdmin setup script wouldn’t know it was being invoked over HTTPS, and when you tried to log in it would try to forward you to the HTTPS url, which is the same page you had just requested. That would push you into an infite redirect loop.

In fact, that’s exactly what was happening. You can fix this with a simple addition to your nginx.conf file:

server {
    listen 443;
    ... more config here, include SSL ...
    location ~ \.php$ {
        ... FastCGI config here ...
        fastcgi_param HTTPS on;
    }
}

That fastcgi_param HTTPS on; line does the trick. Now the PHP script knows it’s being invoked over SSL and doesn’t try to infinitely redirect you. Awesome.