A reverse proxy is a way to expose an internal webserver to the outside world without actually. I do a lot of web development or run test webservers which use a hostname of “localhost” or “127.0.0.1”. Sites and services using those hostnames are not accessible from other computers on the network. Sometimes, I need to run something locally but share it publicly. For example, I may need to demo or test a product on another computer. This article documents how to setup a reverse proxy on Windows Azure using Nginx.
I’m using the following for this example:
- Azure virtual machine running Windows Server
- Nginx for Windows (download)
- A website running locally
- I use the following example: http://127.0.0.1:11235
Step 1 : Open the port in Azure Portal
- Log in to your Azure portal and select your virtual machine
- Create a new stand-alone endpoint
- Endpoints -> Add
- For this example we’re not using a cluster of servers, so leave it as a stand-alone endpoint.
- Next, add your endpoint details
- Name
- Use some easy to remember name
- Protocol
- Leave this as TCP
- Public Port
- The external port you’ll connect to
- e.g. http://<Your VM Name>.cloudapp.net:<External Port>
- The external port you’ll connect to
- Private Port
- For most cases, this will be same as the public port
- Name
Step 2: Setup Nginx
- Copy the Nginx zip file to the VM (download)
- Unzip the file
- Go to the “conf” folder
- Create a new file named “proxy.conf” with the following content:
-
proxy_redirect off; #proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffers 32 4k;
- You may or may not need line #2 from above. Some internal servers will choke if you pass the host header around.
-
- Update the nginx.conf with the following
- server {
listen 81;
server_name <You VM Name>.cloudapp.net localhost;location / {
proxy_pass http://127.0.0.1:11235/;
include proxy.conf;
}}- This instructs Nginx to listen on port 81 and serve up content from 127.0.0.1:11235
- server {
Step 3: Start and test the proxy
- Run nginx.exe from the command-line
- Open a browser and navigate to http:<You VM Name>.cloudapp.net:<External Port>
- You should see your local content published but with the new hostname and port
- Check the Nginx logs if you have any errors.
Feel free to contact me if you have questions or need help.