From bcf4c14c54271fae9ebabc16401d8a78e56a0fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E9=80=B8=E8=BE=B0?= Date: Sat, 15 Jan 2022 21:23:13 +0800 Subject: [PATCH] Update nginx conf (#46) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * set subdomain for admin and mini separately * refactor subdomains * merge master * 添加微信校验配置 * update host config --- dev/admin.conf | 68 ++++++++++++ music-room-dev.conf => dev/music-room.conf | 28 +++-- music-room-test.conf | 123 --------------------- 3 files changed, 84 insertions(+), 135 deletions(-) create mode 100644 dev/admin.conf rename music-room-dev.conf => dev/music-room.conf (77%) delete mode 100644 music-room-test.conf diff --git a/dev/admin.conf b/dev/admin.conf new file mode 100644 index 0000000..150aa0c --- /dev/null +++ b/dev/admin.conf @@ -0,0 +1,68 @@ +server { +# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx# +# server_name $servername; + server_name "admin.moicen.com"; + listen 443 ssl; + client_max_body_size 10M; + + # disable in local test env + ssl_certificate /etc/letsencrypt/live/admin.moicen.com/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/admin.moicen.com/privkey.pem; # managed by Certbot + + set $tmp_file_dir "/file_upload/"; # 文件存储路径 + set $task_server "http://127.0.0.1:8080"; # task server host + set $htyuc "http://127.0.0.1:3000"; #htyuc host + set $resty_loc "/usr/local/openresty"; + set $convert "/usr/bin/convert"; + + location / { + try_files $uri $uri/ /index.html; + proxy_set_header Host "admin.moicen.com"; + proxy_set_header X-Real-IP $remote_addr; + # disable in local test env + proxy_set_header X-Forwarded-Proto https; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Host $remote_addr; + } + + root $resty_loc/nginx/html/admin; + index index.html; + + #Upload image files + location /api/ngx/image/upload { + content_by_lua_file $resty_loc/resty_funcs/upload.lua; + } + #Combine image files + location /api/ngx/image/combine { + content_by_lua_file $resty_loc/resty_funcs/combine.lua; + } + #Audio file download + location /api/ngx/audio/upload { + content_by_lua_file $resty_loc/resty_funcs/upload_audio.lua; + } + #Audio file convert + location /api/ngx/audio/convert { + content_by_lua_file $resty_loc/resty_funcs/convert_audio.lua; + } + + location /api/v1/ws/ { + proxy_pass http://127.0.0.1:3001/api/v1/ws/; + proxy_set_header Host $host; + } + location /api/v1/uc/ { + proxy_pass http://127.0.0.1:3000/api/v1/uc/; + proxy_set_header Host $host; + } + location /api/v1/ts/ { + proxy_pass http://127.0.0.1:8080/api/v1/ts/; + proxy_set_header Host $host; + } +} + +server { + listen 80; + server_name "admin.moicen.com"; + location / { + return 301 https://$host$request_uri; + } +} \ No newline at end of file diff --git a/music-room-dev.conf b/dev/music-room.conf similarity index 77% rename from music-room-dev.conf rename to dev/music-room.conf index fb2b39a..54c1a2b 100644 --- a/music-room-dev.conf +++ b/dev/music-room.conf @@ -1,13 +1,13 @@ server { # https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx# # server_name $servername; - server_name "test-music-room.moicen.com"; + server_name "music-room.moicen.com"; listen 443 ssl; client_max_body_size 10M; # disable in local test env - ssl_certificate /etc/letsencrypt/live/test-music-room.moicen.com/fullchain.pem; # managed by Certbot - ssl_certificate_key /etc/letsencrypt/live/test-music-room.moicen.com/privkey.pem; # managed by Certbot + ssl_certificate /etc/letsencrypt/live/music-room.moicen.com/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/music-room.moicen.com/privkey.pem; # managed by Certbot set $tmp_file_dir "/file_upload/"; # 文件存储路径 set $task_server "http://127.0.0.1:8080"; # task server host @@ -24,7 +24,7 @@ server { location / { try_files $uri $uri/ /index.html; - proxy_set_header Host "test-music-room.moicen.com"; + proxy_set_header Host "music-room.moicen.com"; proxy_set_header X-Real-IP $remote_addr; # disable in local test env proxy_set_header X-Forwarded-Proto https; @@ -35,10 +35,14 @@ server { root $resty_loc/nginx/html/music-room; index index.html; - location /mini/ { - alias $resty_loc/nginx/html/mini-music-room/; - try_files $uri $uri/ /mini/index.html; - index index.html; + # 公众号校验 + location /MP_verify_Jo6pKmy43wx7S5Sh.txt { + return 200 'Jo6pKmy43wx7S5Sh'; + } + + # 小程序业务域名校验 + location /Q25f8xC3Jo.txt { + return 200 '323072b225a694281cd23496fa6737ef'; } #Upload image files @@ -72,21 +76,21 @@ server { location /api/v1/ws/ { proxy_pass http://127.0.0.1:3001/api/v1/ws/; - proxy_set_header Host "test-music-room.moicen.com"; + proxy_set_header Host $host; } location /api/v1/uc/ { proxy_pass http://127.0.0.1:3000/api/v1/uc/; - proxy_set_header Host "test-music-room.moicen.com"; + proxy_set_header Host $host; } location /api/v1/ts/ { proxy_pass http://127.0.0.1:8080/api/v1/ts/; - proxy_set_header Host "test-music-room.moicen.com"; + proxy_set_header Host $host; } } server { listen 80; - server_name "test-music-room.moicen.com"; + server_name "music-room.moicen.com"; location / { return 301 https://$host$request_uri; } diff --git a/music-room-test.conf b/music-room-test.conf deleted file mode 100644 index 993dd7b..0000000 --- a/music-room-test.conf +++ /dev/null @@ -1,123 +0,0 @@ -# MacOS: -# -# ➤ brew install openresty/brew/openresty -# -# EXEC: -# -# ➤ which openresty -# /usr/local/bin/openresty -# -# Config: -# -# ➤ ls /usr/local/etc/openresty -# fastcgi.conf nginx.conf -# fastcgi.conf.default nginx.conf.default -# fastcgi_params scgi_params -# fastcgi_params.default scgi_params.default -# koi-utf uwsgi_params -# koi-win uwsgi_params.default -# mime.types win-utf -# mime.types.default -# -# Main: -# -# ➤ ls /usr/local/opt/openresty -# COPYRIGHT -# INSTALL_RECEIPT.json -# README.markdown -# bin -# homebrew.mxcl.openresty.plist -# luajit -# lualib -# nginx -# pod -# resty.index -# site -server { - server_name "test.localhost"; - listen 8088; - client_max_body_size 10M; - - # disable in local test env - # ssl_certificate /etc/letsencrypt/live/music-room.alchemy-studio.cn/fullchain.pem; # managed by Certbot - # ssl_certificate_key /etc/letsencrypt/live/music-room.alchemy-studio.cn/privkey.pem; # managed by Certbot - - # https://fishshell.com/docs/current/language.html#variable-expansion - # ➤ mkdir -p /usr/local/file_upload - # ➤ sudo chown (whoami) /usr/local/file_upload - set $tmp_file_dir "/usr/local/file_upload"; # 文件存储路径 - set $task_server "http://127.0.0.1:8080"; # task server host - set $htyuc "http://127.0.0.1:3000"; #htyuc host - - set $upyun_operator "moicen"; - set $upyun_password "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN"; - set $upyun_bucket "huiwing"; - set $upyun_directory "music-room"; - set $upyun_cdn "https://upyun.alchemy-studio.cn/music-room/"; - set $upyun_api "https://v2.api.upyun.com"; - - #set $resty_loc "/usr/local/opt/openresty"; # MacOS - set $resty_loc "/usr/local/openresty"; # CentOS - set $convert "/usr/local/bin/convert"; - - location / { - try_files $uri $uri/ /index.html; - proxy_set_header Host "test.localhost"; - proxy_set_header X-Real-IP $remote_addr; - # disable in local test env - proxy_set_header X-Forwarded-Proto https; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Forwarded-Host $remote_addr; - } - - root $resty_loc/nginx/html/music-room; - index index.html; - - location /mini/ { - alias $resty_loc/nginx/html/mini-music-room/; - try_files $uri $uri/ /mini/index.html; - index index.html; - } - - #Upload image files - location /api/ngx/image/upload { - content_by_lua_file $resty_loc/resty_funcs/upload.lua; - } - #Combine image files - location /api/ngx/image/combine { - content_by_lua_file $resty_loc/resty_funcs/combine.lua; - } - #Audio file download - location /api/ngx/audio/upload { - content_by_lua_file $resty_loc/resty_funcs/upload_audio.lua; - } - #Audio file convert - location /api/ngx/audio/convert { - content_by_lua_file $resty_loc/resty_funcs/convert_audio.lua; - } - #Upyun token - location /api/ngx/upyun/token{ - content_by_lua_file $resty_loc/resty_funcs/upyun_token.lua; - } - #Static file server - location /file_upload { - default_type ""; - alias $tmp_file_dir; - autoindex on; - autoindex_exact_size off; - autoindex_localtime on; - } - - location /api/v1/ws/ { - proxy_pass http://127.0.0.1:3001/api/v1/ws/; - proxy_set_header Host $host; - } - location /api/v1/uc/ { - proxy_pass http://127.0.0.1:3000/api/v1/uc/; - proxy_set_header Host $host; - } - location /api/v1/ts/ { - proxy_pass http://127.0.0.1:8080/api/v1/ts/; - proxy_set_header Host $host; - } -}