Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using nginx as a reverse proxy to IIS server

Tags:

nginx

asp.net

iis

I have multiple ASP.NET applications running on a single IIS server with different ports for each application.

I have installed nginx on the same server so that my clients can access all my applications only using port 80.

Nginx is running all right on port 80. My individual ASP.NET applications are also up and running.

I made these changes in nginx conf file

    location /students/ {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:84;
    }
    location /registration/ {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:82;
    }

Then I restarted nginx and typed the url http://127.0.0.1/students/ in my browser. Nginx served a 404 page.

I made no other changes to the conf file.

What I am doing wrong?

like image 839
Shuaib Avatar asked Oct 20 '15 01:10

Shuaib


People also ask

Can NGINX be used as reverse proxy?

The benefits of using Nginx as a reverse proxy include: Clients access all backend resources through a single web address. The reverse proxy can serve static content, which reduces the load on application servers such as Express, Tomcat or WebSphere.

Does IIS have reverse proxy?

By default, IIS does not come with reverse proxy routing capability. To enable it, we need to manually install certain extensions first. Click the links below to download & install the extensions. After installing the extensions, you should see an option URL Rewrite added to the IIS dashboard under Default Web Site .

Can NGINX be used as proxy server?

NGINX was initially designed as a reverse proxy server. However, with continuous development, NGINX also serves as one of the options to implement the forward proxy. The forward proxy itself is not complex, the key issue it addresses is how to encrypt HTTPS traffic.


1 Answers

I believe that the problem you are having is related to the start of the URL path. Does the URL http://120.0.0.1:84/students/ return the page, or a 404? If you are expecting to go to http://127.0.0.1:80/students/ and see the page at http://127.0.0.1/, you will find that nginx does not transform the path for you with this configuration. Rather, it looks for exactly the same path at the proxied server.

You need to put the / on the end of the URL in the proxy_pass directive:

location /students/ {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:84/;
}

This is a subtle but important gotcha in nginx configs! If you don't include the backslash, http://127.0.0.1:84 will be treated as a server location. If you do have the backslash, it will be regarded as a URL, and it will replace everything in the proxy URL up to the 'location' part.

like image 83
jwg Avatar answered Oct 11 '22 16:10

jwg