Last active
November 25, 2023 16:39
-
-
Save jaysonlong/55479cac2f493d10bd7b6160f05f1198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function write_http_conf() { | |
cat > ./nginx.conf << EOF | |
server { | |
error_log /var/log/nginx/error.log; | |
access_log /var/log/nginx/access.log; | |
rewrite ^/$ /haha-music/ redirect; | |
rewrite ^/haha-music$ /haha-music/ redirect; | |
rewrite ^/goudan-music$ /goudan-music/ redirect; | |
location /haha-music/ { | |
proxy_pass http://haha-music/; | |
} | |
location /goudan-music/ { | |
proxy_pass http://goudan-music/; | |
} | |
} | |
EOF | |
} | |
function write_https_conf() { | |
cat > ./nginx.conf << EOF | |
server { | |
listen 80; | |
rewrite ^(.*)$ https://\$host\$1 permanent; | |
} | |
server { | |
listen 443 ssl; | |
ssl_certificate /etc/letsencrypt/live/jaysonl.top/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/jaysonl.top/privkey.pem; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; | |
ssl_ciphers HIGH:!aNULL:!MD5; | |
rewrite ^/$ /haha-music/ redirect; | |
rewrite ^/haha-music$ /haha-music/ redirect; | |
rewrite ^/goudan-music$ /goudan-music/ redirect; | |
location /haha-music/ { | |
proxy_pass http://haha-music/; | |
} | |
location /goudan-music/ { | |
proxy_pass http://goudan-music/; | |
} | |
} | |
EOF | |
} | |
function setup() { | |
write_http_conf | |
docker stop base-server && docker rm base-server > /dev/null 2>&1 | |
docker network create entrance > /dev/null 2>&1 | |
docker create --name base-server --net entrance -p 80:80 \ | |
-v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf nginx:1.24.0 | |
docker network connect haha-music base-server | |
docker network connect goudan-music base-server | |
docker start base-server | |
} | |
function setupssl() { | |
write_https_conf | |
docker stop base-server && docker rm base-server > /dev/null 2>&1 | |
docker network create entrance > /dev/null 2>&1 | |
docker create --name base-server --net entrance -p 80:80 -p 443:443 \ | |
-v /etc/letsencrypt:/etc/letsencrypt \ | |
-v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf nginx:1.24.0 | |
docker network connect haha-music base-server | |
docker network connect goudan-music base-server | |
docker start base-server | |
} | |
if [ "$1" = "setup" ]; then | |
setup | |
elif [ "$1" = "up" ]; then | |
docker start base-server | |
elif [ "$1" = "stop" ]; then | |
docker stop base-server | |
elif [ "$1" = "setupssl" ]; then | |
setupssl | |
else | |
echo unknown option $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment