Posts Tagged ‘visual studio’

nginx as a proxy for Visual Studio

Tuesday, January 26th, 2010

I guess most people doing ASP.NET web development in Visual Studio (VS) have been frustrated by the fact that the development server in VS only wants to serve it’s content to the local machine. It is inaccessible from other computers on the network and impossible to reach from a Virtual Machine running alternative configurations of OS/browser. This is a pain in the ass when trying to debug something not working in another version of Internet Explorer than you have on your local machine.

We’ve been trying different approaches to circumvent this, using SSH tunnels and other similar technologies, without any luck. But this morning I came up with a solution: A local HTTP proxy in front of the development server. This way, anybody can access the proxy, and still all requests to the development server are local. I chose nginx (pronounced engine x) as the proxy. It’s free, open source and it only takes a couple minutes to get up and running.

Download

Currently, the most recent version of nginx for Windows is 0.8.32, and it is available for download here. It’s a simple zip file that just needs to be extracted. No installation is needed — the server runs directly from the uncompressed files.

Configuration

In the folder conf, there’s file called nginx.conf. This is the configuration file for nginx.

Around line 36 it says:

listen 80;
server_name localhost;

80 is the port number nginx is listening to. I have personally chosen to change this to 8080, as I already have a local Apache server running on port 80. But you can pick any port number you like, as long as it’s not in use.

Around line 43 it says:

location / {
root html;
index index.html index.htm;
}

Change this to:

location / {
#root html;
#index index.html index.htm;
proxy_pass http://localhost:xxxx;
}

Where xxxx is the port on which VS is running it’s development server. This changes from project to project, and even changes from time to time in a project. So this will need to be changed once in while.

Start and reload

nginx is started by double clicking the file nginx.exe, or by opening a command prompt, cd to the nginx folder and run the command start nginx.exe. If everything is fine (i.e. if you didn’t make any mistakes in the configuration), you will hereafter have 2 new processes (a master and a worker) running, both called nginx.exe.

If you need to reconfigure nginx (e.g. change to a new port VS has chosen to run it’s server at), afterwards you can reload nginx by running the command nginx -s reload from the nginx folder in command prompt.

Read more about start, reload and stop in the official documentation.

Access

The VS development server is now available — through nginx — at http://HOSTNAME:8080, where HOSTNAME is the network name (or IP address) of your computer, and 8080 is the port you chose to let nginx listen to in the configuration.

Happy external debugging.