Skip to content

Instantly share code, notes, and snippets.

@sigmadream
Last active November 18, 2024 16:31
Show Gist options
  • Save sigmadream/f033f2b5476e5528ebce4b795e46648a to your computer and use it in GitHub Desktop.
Save sigmadream/f033f2b5476e5528ebce4b795e46648a to your computer and use it in GitHub Desktop.

HTTPS 인증서

  • certbot를 사용해서 인증서 발급
sudo certbot certonly --manual --preferred-challenges dns -d "*.codemetrics.app" -d "codemetrics.app"

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for *.codemetrics.app and codemetrics.app

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.codemetrics.app.

with the following value:

2z4-4CRbIRBj_VPGTakTiA9duft8We7MK9GfOVBqCQE

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.codemetrics.app.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/codemetrics.app/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/codemetrics.app/privkey.pem
This certificate expires on 2025-02-13.
These files will be updated when the certificate renews.

NEXT STEPS:
- This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • /etc/letsencrypt/live/codemetrics.app/fullchain.pem
  • /etc/letsencrypt/live/codemetrics.app/privkey.pem

Nginx 수정

  • /etc/nginx/sites-available/default
server {
    	server_name codemetrics.app;
    	listen 443 ssl default_server;
    	listen [::]:443 ssl default_server;
    	
      ssl_certificate /etc/letsencrypt/live/codemetrics.app/fullchain.pem;
    	ssl_certificate_key /etc/letsencrypt/live/codemetrics.app/privkey.pem;

    	root /var/www/html;
    	index index.html index.htm index.nginx-debian.html;

    	location / {
            	# First attempt to serve request as file, then
            	# as directory, then fall back to displaying a 404.
            	try_files $uri $uri/ =404;
    	}
}

Proxy

...
server {
    listen        80;
    server_name   example.com *.example.com;
    location / {
        proxy_pass         http://127.0.0.1:5000/;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection $connection_upgrade;
        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;
    }
}
...

systemd

sudo vi /etc/systemd/system/asp-net.service

[Unit]
Description=Example .NET Web API App running on Linux

[Service]
WorkingDirectory=/var/www/aspnet
ExecStart=/usr/bin/dotnet /var/www/aspnet/helloapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_NOLOGO=true

[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment