Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nginx and ASP.Net Core

121 views
Skip to first unread message

Patrick Kirk

unread,
Dec 13, 2021, 6:40:05 AM12/13/21
to
Hi all,

I am trying to run an ASP.Net Core site on my hosted Debian box and I seem to have messed up the configuration.  All attempts to reach the page on port 80 get 403 Forbidden messages.

My error log says: pk@debian-s-websites:~$ sudo tail -f /var/log/nginx/error.log 2021/12/13 06:27:24 [error] 17999#17999: *675 directory index of "/var/www/cxxxn.org/" is forbidden, client: 213.7.43.53, server: cxxxn.org, request: "GET / HTTP/1.1", host: "www.cxxxn.org"

If I try lynx http://localhost:5000 locally I get a perfect session. So kestrel is working but nginx is not configured correctly. I think the mistake is in my the config file for cxxxn.org has a line saying: "index index.html index.htm index.nginx-debian.html" To test this, I put a <html>Hello World</html> file in the root folder and it was served up correctly. If I then try http://cxxxn.org/Privacy I get a 404 error.

Does anyone know if my guess that the "index" line in the configuration is the problem is correct?

How can I configure Nginx to serve content from Asp.Net Core where there is no static html file being generated?

Thanks in advance.

Patrick Kirk

unread,
Dec 13, 2021, 7:10:05 AM12/13/21
to

On Mon, 13 Dec 2021 at 13:37, Dan Ritter <d...@randomstring.org> wrote:
Patrick Kirk wrote:

6. If serving dynamic content, where to get it


A program running on port 5000 is a fine place to serve dynamic
content from, but you haven't told nginx about it.

I'll bet you that this "kestrel" program comes with
documentation about using a reverse proxy, which is what you
want nginx to do.

-dsr-
Hi Dan,

Nginx is working well for items 1 to 6 on your list.  I followed this tutorial: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-6.0

As you can see from the logs, there is no problem serving static files.

But I can't find how to tell nginx where to get dynamic content.

Dan Ritter

unread,
Dec 13, 2021, 7:10:05 AM12/13/21
to
In /etc/nginx/site-enabled/ you need to put a config file that
unambiguosly tells nginx:

1. which DNS name(s) to serve from this config

2. what ports

3. what protocols

4. If using SSL/TLS, which certs and algorithms

5. If serving static content, where to begin

Dan Ritter

unread,
Dec 13, 2021, 7:40:05 AM12/13/21
to
It's right in that tutorial:

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;
}
0 new messages