V
V
Victor P.2018-07-11 11:52:16
linux
Victor P., 2018-07-11 11:52:16

How to work with reverse proxy for .net?

I have a .net core project and for educational purposes I want to host it on linux. Now I’m reading how it’s all done, and, the most competent bunch, when we deploy .net on the built-in Kestrel server or even as self hosted, and put a reverse proxy on Nginx in front of it. And in words, everything turns out fine, since Nginx takes over part of the work, for example, gives static, which unloads the main server.
But please clarify this point. I have images. There is a database with two tables: a meta description (id, title, alt, path on the server) and a backup table with an ID and a healthy binary of the image itself. The display of the picture goes through the controller, that is, I first check if there is a picture on the server at the desired address, if there is, then I give it away, if not, then I get a backup from the database, save it on the server in several formats and give the right one back. The operation, when I get the backup, is long, but it works if the server has moved or someone messed up and deleted something, or just the dev / prod is loaded automatically, that is, it will work once in normal mode.
The bottom line is, as far as I understand, if a request for statics comes in, then Nginx simply climbs along the right path on the server and returns the picture. Accordingly, if there is no picture, it will return 404.
But you need to make it so that if there is no picture, in order to forward the request to the main server, is it possible to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2018-07-11
@Jeer

Yes, you can. More or less like this.

...
location /images/ {
    try_files $uri @mysite;
}
...
location @mysite {
...
   proxy_pass http://localhost:8080;
...
}

If there is no image in /images, then proxying to localhost:8080 will work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question