Nginx how can I do Reverse Proxy to my .NET Core Web API?

97 Views Asked by At

I created a simple API application for experimental purposes with .NET Core and uploaded it to a cPanel. I ran the .NET Core application from the terminal and added it as a service. Currently it is working on Kestrel.

When I send a GET request to the API using the path 'http://localhost:7202/Example' on my computer, I see a simple string value in my browser as a result.

image from localhost on my computer

I want to do the same with my AlmaLinux server by setting up a Reverse Proxy process so that I can access it via my domain, like 'http://domain-name.com/Example'. In other words, when I access it in this format, I want to see the result of the corresponding GET operation in my browser.

I have provided the content of the Reverse Proxy configuration file I created with Nginx below.

server {
    listen 80;
    server_name domain-name.com www.domain-name.com;
    #listen 80 default_server;
    #listen [::]:80 default_server;
    location / {
     proxy_pass http://127.0.0.1:5000;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection keep-alive;
     proxy_set_header Host $host;
     proxy_cache_bypass $http_upgrade;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Currently, when I go to http://domain-name.com/Example in my browser, it redirects me to https://domain-name.com:5001/.

I've tried different configuration files, but I'm getting the same result in all of them

Thanks in advance.

0

There are 0 best solutions below