Skip to content

Conversation

@mguinness
Copy link

Adds a template for ASP.NET Core website exposing http port to be be proxied as https with a Duck DNS subdomain. Hopefully this can help someone else trying to get a secure website up and running via nginx reverse proxy and letsencrypt certificate.

@nemchik
Copy link
Member

nemchik commented Sep 8, 2020

Sorry for not getting to this sooner. This looks similar enough to our other proxy samples that I wonder if you could try this config and if it works?

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name <container_name>.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth, fill in ldap details in ldap.conf
    #include /config/nginx/ldap.conf;

    # enable for Authelia
    #include /config/nginx/authelia-server.conf;

    location / {
        # enable the next two lines for http auth
        #auth_basic "Restricted";
        #auth_basic_user_file /config/nginx/.htpasswd;

        # enable the next two lines for ldap auth
        #auth_request /auth;
        #error_page 401 =200 /ldaplogin;

        # enable for Authelia
        #include /config/nginx/authelia-location.conf;

        include /config/nginx/proxy.conf;
        resolver 127.0.0.11 valid=30s;
        set $upstream_app <container_name>;
        set $upstream_port 80;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    }
}

Note the <container_name> in two places should be replaced.

@mguinness
Copy link
Author

The sample is mostly taken from Microsoft documentation Configure Nginx, but I did have to change the following line:

proxy_set_header Connection keep-alive;
to
proxy_set_header Connection $http_connection;

This was needed to allow SignalR in ASP.NET Core behind Nginx. The configuration works well for me which is why I wanted to share with others.

@nemchik
Copy link
Member

nemchik commented Sep 9, 2020

We've just recently updated our nginx.conf and proxy.conf in the swag repo to properly handle websockets (including SignalR). linuxserver/docker-swag#7 has the changes. If you have not modified your nginx.conf and proxy.conf you can simply delete them and restart the container. Otherwise you can review the PR and change your files accordingly. proxy.conf is included in most (if not all) of the proxy samples in this repo, and the example I posted above, so websockets should work correctly if you apply the changes to the files. Once that's done if you could confirm if the above proxy sample works for you we can consider how to add this so that it makes sense.

We already have a few .NET application proxies in the repo such as sonarr, radarr, and lidarr. Radarr uses SignalR (and maybe the others do as well) and the PR on the swag repo was actually started to resolve issues with SignalR not working, and after some research I found the recommended way to handle websockets from nginx's documentation. The nginx recommended method is in line with the Microsoft recommended method, so they should both handle websockets (including SignalR). I can confirm with our current configs (nginx.conf, proxy.conf, and for example radarr.subfolder.conf) SignalR seems to be working fine for me.

@mguinness
Copy link
Author

mguinness commented Sep 9, 2020

OK, thanks for addressing the websockets issue. I'll close this PR if you already have a sample for aspnetcore.

@mguinness mguinness closed this Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants