From 39c5787773aa02b80dfa10553bf5099599b69e8d Mon Sep 17 00:00:00 2001 From: Baohua Yang Date: Wed, 2 Feb 2022 17:46:21 -0800 Subject: [PATCH] Add nginx https sample --- nginx/nginx_https/docker-compose.yml | 18 +++++++++ nginx/nginx_https/nginx.conf | 55 ++++++++++++++++++++++++++++ nginx/nginx_https/ssl/gen_certs.sh | 9 +++++ nginx/nginx_https/ssl/server.crt | 21 +++++++++++ nginx/nginx_https/ssl/server.key | 28 ++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 nginx/nginx_https/docker-compose.yml create mode 100644 nginx/nginx_https/nginx.conf create mode 100644 nginx/nginx_https/ssl/gen_certs.sh create mode 100644 nginx/nginx_https/ssl/server.crt create mode 100644 nginx/nginx_https/ssl/server.key diff --git a/nginx/nginx_https/docker-compose.yml b/nginx/nginx_https/docker-compose.yml new file mode 100644 index 00000000..78e4b390 --- /dev/null +++ b/nginx/nginx_https/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3' +services: + nginx: + image: nginx:1.20 + container_name: nginx + volumes: + - ./nginx.conf:/etc/nginx/nginx.conf + - ./ssl:/etc/nginx/ssl + ports: + - 80:80 + - 443:443 + + app: + image: python:3.7 + container_name: app + expose: + - "80" + command: python3 -m http.server 80 diff --git a/nginx/nginx_https/nginx.conf b/nginx/nginx_https/nginx.conf new file mode 100644 index 00000000..aba04d32 --- /dev/null +++ b/nginx/nginx_https/nginx.conf @@ -0,0 +1,55 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + #gzip on; + + #include /etc/nginx/conf.d/*.conf; + + upstream backend { + server app:80; + } + + server { + listen 80; + location / { + proxy_pass http://backend; + } + } + + server { + listen 443 ssl; + + ssl_trusted_certificate /etc/nginx/ssl/server.crt; + ssl_certificate /etc/nginx/ssl/server.crt; + ssl_certificate_key /etc/nginx/ssl/server.key; + location / { + proxy_pass http://backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + } +} \ No newline at end of file diff --git a/nginx/nginx_https/ssl/gen_certs.sh b/nginx/nginx_https/ssl/gen_certs.sh new file mode 100644 index 00000000..6eebb504 --- /dev/null +++ b/nginx/nginx_https/ssl/gen_certs.sh @@ -0,0 +1,9 @@ +openssl req \ + -x509 \ + -nodes \ + -days 3650 \ + -newkey rsa:2048 \ + -keyout /root/server.key \ + -out /root/server.crt + +# Enter "*.com" (without quotes) as "Common Name" diff --git a/nginx/nginx_https/ssl/server.crt b/nginx/nginx_https/ssl/server.crt new file mode 100644 index 00000000..93008b98 --- /dev/null +++ b/nginx/nginx_https/ssl/server.crt @@ -0,0 +1,21 @@ +-----BEGIN CERTIFICATE----- +MIIDfTCCAmWgAwIBAgIURFu7iX8+iLUXefTUMhV5HkviJJ8wDQYJKoZIhvcNAQEL +BQAwTjELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMQowCAYDVQQHDAFPMQowCAYD +VQQKDAFPMQowCAYDVQQLDAFPMQ4wDAYDVQQDDAUqLmNvbTAeFw0yMjAyMDIyMzU0 +MjFaFw0zMjAxMzEyMzU0MjFaME4xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTEK +MAgGA1UEBwwBTzEKMAgGA1UECgwBTzEKMAgGA1UECwwBTzEOMAwGA1UEAwwFKi5j +b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDRVhWlCMpKJAaWVI+U +aOF82vttfGECi28ZdUqgeaQnniOxGC2fQ66pJSmltTiYVTH3IRRbax/pGgUdqt1E +gGB2jLqqbcqMxlzg4mSThO/cT2/3cFjoeOyg6yC2RjB8FjTjFrkWqiEenubqnqSX +DC7XB6icYuimRPhMCLhC6GX/nPwfTMc98vzi9icOVZet84s5pReRQcSEd5ndg5+L +OnCgivwFSXsjVZudpojXmdZ2Izb9fVQAhKZTgHe62rF1RZ2wkAmnOo1Haybe89vN +Cm8lbIcoQKgPFlsqt3fa1kL80opHwrj6wDVMZ1dXGLULZ1EdGowymgso29o+Ojuh +3n2NAgMBAAGjUzBRMB0GA1UdDgQWBBQkfe744BxH3XaZlWvXq54YFmp9MDAfBgNV +HSMEGDAWgBQkfe744BxH3XaZlWvXq54YFmp9MDAPBgNVHRMBAf8EBTADAQH/MA0G +CSqGSIb3DQEBCwUAA4IBAQCuH6jvESJQAzBGnKTHNlLmaX5OWJ2tFx78mRkLgbPC +kL1uTwH7aQfga+TjnEPT5rSftnATaR0k8vxLSIT3KEpHrFZ4hHr1UwqikJGkmAYa +TlFXLvX8eX8bo6NxECHz7OBOGzvUxBY9tm7NdojHk7XfOY5gJSbnpFQxNcdpk7jd +y56nqAI/zhaDoCcrdxpvEBT657+NAaBfCJeH8ivudAQffaAJ9/c68HWHCr+tyQQw +Vr6s6QMMKAZWJhUNKFVhNZczT+WcpqbQEuab1LJsut4pm72CUayq92vm7+jwiyCP +TaKrNkcWug74xzzxvZtvtAO8rKRjyI/VZRB8sT6W2ey6 +-----END CERTIFICATE----- diff --git a/nginx/nginx_https/ssl/server.key b/nginx/nginx_https/ssl/server.key new file mode 100644 index 00000000..2b40a12f --- /dev/null +++ b/nginx/nginx_https/ssl/server.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDRVhWlCMpKJAaW +VI+UaOF82vttfGECi28ZdUqgeaQnniOxGC2fQ66pJSmltTiYVTH3IRRbax/pGgUd +qt1EgGB2jLqqbcqMxlzg4mSThO/cT2/3cFjoeOyg6y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