跳到主要内容

UMU 学习平台

2024年04月27日
柏拉文
越努力,越幸运

一、认识


本地开发 umu 项目需要经历以下步骤:

  1. 创建项目目录: 在根目录(~)下创建 projects 文件夹,并将代码下载到这下面,无论是使用 docker 还是本地自己搭建环境都是依赖于该目录

  2. NPM 源配置

  3. 本地测试域名代理(本文讲解)

  4. Nginx 域名代理映射配置 (本文讲解)

二、测试域名配置


通过 SwitchHosts 来管理本地 Hosts, Host 配置如下:

127.0.0.1 test.dev07.umucdn.cn  
127.0.0.1 test.m.dev07.umucdn.cn

127.0.0.1 test.dev14.umucdn.cn
127.0.0.1 test.m.dev14.umucdn.cn

127.0.0.1 test.dev15.umucdn.cn
127.0.0.1 test.m.dev15.umucdn.cn

127.0.0.1 test.dev16.umucdn.cn
127.0.0.1 test.m.dev16.umucdn.cn

127.0.0.1 test.dev19.umucdn.cn
127.0.0.1 test.m.dev19.umucdn.cn

127.0.0.1 test.dev20.umucdn.cn
127.0.0.1 test.m.dev20.umucdn.cn

127.0.0.1 test.dev24.umucdn.cn
127.0.0.1 test.m.dev24.umucdn.cn

127.0.0.1 test.dev26.umucdn.cn
127.0.0.1 test.m.dev26.umucdn.cn

127.0.0.1 test.dev32.umucdn.cn
127.0.0.1 test.m.dev32.umucdn.cn

127.0.0.1 test.dev44.umucdn.cn
127.0.0.1 test.m.dev44.umucdn.cn

127.0.0.1 test.dev58.umucdn.cn
127.0.0.1 test.m.dev58.umucdn.cn

127.0.0.1 test.dev59.umucdn.cn
127.0.0.1 test.m.dev59.umucdn.cn

三、域名映射配置


3.1 nginx.conf

user root admin;
worker_processes 1;

events {
worker_connections 1024;
}

http {
sendfile on;
include mime.types;
keepalive_timeout 1000;
client_max_body_size 1024m;
client_header_buffer_size 1024m;
server_names_hash_bucket_size 64;
default_type application/octet-stream;

# access_log logs/access.log;
# error_log logs/error.log debug;

server {
listen 80;
server_name localhost;
location / {
root /Users/zhangwenqiang/projects/;
index index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen 80;
server_name test.bolawen.com;
location / {
root /Users/zhangwenqiang/bolawen/;
index index.html index.htm;
}
location /server {
rewrite ^/server/(.*) /$1 break;
proxy_pass http://localhost:4000;
}
}

include local_proxy.nginx.conf;
include node-nginx.conf;
include servers/*;
}

3.2 node_location

set $node_port 7001;
set $local_host 192.24.12.84;

location ^~ /default {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /umu {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /element {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /activity/annual2018 {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /activity/annual2019 {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/document {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}


location ^~ /session/infographic {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/video {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/discuss {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/article {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/ask {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/photo {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}


location ^~ /class/share-to-space {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /homework/evaluate {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/quiz {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}


location ^~ /napi/ {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ~* ^/course {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /session/audioslides {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /novartis {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /nwapi {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /echo {
return 200 $name;
}

location ^~ /register {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /program/rank {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ~ /session/live/([^\/].*)/edit {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /activity/influenceShare {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location ^~ /profile/assignment {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location ^~ /page {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location ^~ /favorite {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location ^~ /course {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location ^~ /main {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location /cms {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}
location /view {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location /enroll {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location /learning-circle {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location /learning-map-detail {
proxy_pass http://$local_host:$node_port$request_uri;
proxy_set_header Host $http_host;
}

location / {
proxy_pass http://nodeapi$request_uri;
proxy_set_header Host $http_host;
}

location ^~ /home {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /product {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /download {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /access-denied {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /scorm {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /ai/ {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /assessment {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /profile {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}
location ^~ /market {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

location ^~ /support/browserupgrade {
proxy_pass http://$local_host:$node_port;
proxy_set_header Host $http_host;
}

3.3 node-nginx.conf

# dev08

server {
listen 80;
server_name ntest.dev08.umucdn.cn;
set $name "dev08";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev08.umucdn.cn;
set $name "dev08";

include node_location;
}
# dev11
server {
listen 80;
server_name ntest.dev11.umucdn.cn;
set $name "dev11";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev11.umucdn.cn;
set $name "dev11";

include node_location;
}
# 预览机
server {
listen 80;
server_name ntest.umu.cn;
set $name "umu";

include node_location;
}

server {
listen 80;
server_name ntest.m.umu.cn;
set $name "umu";

include node_location;
}

# dev05

server {
listen 80;
server_name ntest.dev05.umucdn.cn;
set $name "dev05";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev05.umucdn.cn;
set $name "dev05";

include node_location;
}

# dev06

server {
listen 80;
server_name ntest.dev06.umucdn.cn;
set $name "dev08";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev06.umucdn.cn;
set $name "dev08";

include node_location;
}

# dev24

server {
listen 80;
server_name ntest.dev24.umucdn.cn;
set $name "dev24";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev24.umucdn.cn;
set $name "dev24";

include node_location;
}


# dev31

server {
listen 80;
server_name ntest.dev31.umucdn.cn;
set $name "dev31";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev31.umucdn.cn;
set $name "dev31";

include node_location;
}

# dev42

server {
listen 80;
server_name ntest.dev42.umucdn.cn;
set $name "dev42";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev42.umucdn.cn;
set $name "dev42";

include node_location;
}

# dev55

server {
listen 80;
server_name ntest.dev55.umucdn.cn;
set $name "dev55";

include node_location;
}

server {
listen 80;
server_name ntest.m.dev55.umucdn.cn;
set $name "dev55";

include node_location;
}

2.4 local_proxy.nginx.conf

server {
listen 80;
server_name ~test\.dev(\d+)\.umu(cdn)?\.cn$;
set $devValue $1;

listen 443 ssl;
ssl_certificate $ssl_server_name/fullchain1.pem;
ssl_certificate_key $ssl_server_name/privkey1.pem;

location / {
if ( $host ~* test\.(.*) ) {
set $proxyHost $1;
}
if ( $cookie_env_host ~* ON\.(.*) ) {
set $proxyHost $1;
}
if ( $host ~* test\.dev(\d+).umucdn\.cn$ ) {
set $dev $1;
}

resolver 8.8.8.8;
add_header debug-local-flag true;
add_header debug-proxy-host $proxyHost;
proxy_pass http://$proxyHost;
}

location /_projects/ {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
alias /Users/zhangwenqiang/projects/;
}

location /themes/ {
alias /Users/zhangwenqiang/projects/umu_pc/_output/;
}

location /swww/ {
alias /Users/zhangwenqiang/projects/umu_screen/_dist_dev/;
}

location /twww/ {
alias /Users/zhangwenqiang/projects/umu_pc/_output/;
}

location /mobile/ {
alias /Users/zhangwenqiang/projects/umu_mobile/_dist_dev/;
}

location /statics/course/ {
alias /Users/zhangwenqiang/projects/umu_course/dist/;
}

location /statics/learning_task/ {
alias /Users/zhangwenqiang/projects/umu_learning_task/dist/;
}

location /commonMobileModule/ {
alias /Users/zhangwenqiang/projects/umu_mobile/_library/;
}

location /statics/exam/ {
alias /Users/zhangwenqiang/projects/umu_exam/dist/;
}

location /statics/ai_exercise/ {
alias /Users/zhangwenqiang/projects/umu_ai_exercise/dist/;
}

location /statics/ai_audio_slides/ {
alias /Users/zhangwenqiang/projects/umu_ai_audio_slides/dist/;
}

location /statics/platform/ {
alias /Users/zhangwenqiang/projects/umu_plateform/dist/;
}

location /statics/ems {
alias /Users/zhangwenqiang/projects/umu_ems/dist/;
}

location /statics/home {
alias /Users/zhangwenqiang/projects/umu_home/_dist_dev/;
}

location /statics/class {
alias /Users/zhangwenqiang/projects/umu_class/dist/;
}

location /statics/growth{
alias /Users/zhangwenqiang/projects/umu_growth/dist/;
}

location /statics/profile {
alias /Users/zhangwenqiang/projects/umu_profile/dist/;
}

location /statics/pc_course/ {
alias /Users/zhangwenqiang/projects/umu_pc_course/dist/;
}

location /statics/learning_circle/ {
alias /Users/zhangwenqiang/projects/umu_learning_circle/dist/;
}

location /statics/lecturer/ {
alias /Users/zhangwenqiang/projects/umu_lecturer/dist/;
}

location /statics/points-store/ {
alias /Users/zhangwenqiang/projects/umu_points_store/dist/;
}

location /statics/basic_support/ {
alias /Users/zhangwenqiang/projects/umu_basic_support/dist/;
}

location /statics/commercialize/ {
alias /Users/zhangwenqiang/projects/umu_commercialize/dist/;
}

location /statics/market/ {
alias /Users/zhangwenqiang/projects/umu_market/dist/;
}

location /statics/micro_pages/ {
alias /Users/zhangwenqiang/projects/umu_micro_pages/dist/;
}

location /statics/assessment/ {
alias /Users/zhangwenqiang/projects/umu_assessment/dist/;
}

location /statics/auth/ {
alias /Users/zhangwenqiang/projects/umu_auth/dist/;
}

location /statics/search/ {
alias /Users/zhangwenqiang/projects/umu_search/dist/;
}
}


server {
listen 80;
server_name ~test\.m\.dev\d+\.umu(cdn)?\.cn$;
add_header debug-local-flag true;

listen 443 ssl;
ssl_certificate $ssl_server_name/fullchain1.pem;
ssl_certificate_key $ssl_server_name/privkey1.pem;

location /{
if ( $host ~* test\.(.*) ) {
set $proxyHost $1;
}
if ( $cookie_env_host ~* ON\.(.*) ) {
set $proxyHost $1;
}
if ( $host ~* test\.m.\.dev(\d+).umucdn\.cn$ ) {
set $dev $1;
}
resolver 8.8.8.8;
add_header debug-local-flag true;
add_header debug-proxy-host $proxyHost;
proxy_pass http://$proxyhost;
}

location /_projectss/ {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
alias /Users/zhangwenqiang/projects/;
}

location /themes/ {
alias /Users/zhangwenqiang/projects/umu_wap_student/_output/;
}

location /mobile/ {
alias /Users/zhangwenqiang/projects/umu_mobile/_dist_dev/;
}

location /statics/assessment/ {
alias /Users/zhangwenqiang/projects/umu_assessment/dist/;
}

location /statics/course/ {
alias /Users/zhangwenqiang/projects/umu_course/dist/;
}

location /statics/exam/ {
alias /Users/zhangwenqiang/projects/umu_exam/dist/;
}

location /statics/ai_exercise/ {
alias /Users/zhangwenqiang/projects/umu_ai_exercise/dist/;
}

location /statics/ai_audio_slides/ {
alias /Users/zhangwenqiang/projects/umu_ai_audio_slides/dist/;
}

location /statics/platform/ {
alias /Users/zhangwenqiang/projects/umu_plateform/dist/;
}

location /statics/ems {
alias /Users/zhangwenqiang/projects/umu_ems/dist/;
}

location /statics/home {
alias /Users/zhangwenqiang/projects/umu_home/_dist_dev/;
}

location /statics/class {
alias /Users/zhangwenqiang/projects/umu_class/dist/;
}

location /statics/growth{
alias /Users/zhangwenqiang/projects/umu_growth/dist/;
}

location /statics/profile {
alias /Users/zhangwenqiang/projects/umu_profile/dist/;
}

location /statics/pc_course/ {
alias /Users/zhangwenqiang/projects/umu_pc_course/dist/;
}

location /statics/learning_circle/ {
alias /Users/zhangwenqiang/projects/umu_learning_circle/dist/;
}

location /statics/lecturer/ {
alias /Users/zhangwenqiang/projects/umu_lecturer/dist/;
}

location /statics/points-store/ {
alias /Users/zhangwenqiang/projects/umu_points_store/dist/;
}

location /statics/basic_support/ {
alias /Users/zhangwenqiang/projects/umu_basic_support/dist/;
}

location /statics/commercialize/ {
alias /Users/zhangwenqiang/projects/umu_commercialize/dist/;
}

location /statics/market/ {
alias /Users/zhangwenqiang/projects/umu_market/dist/;
}

location /statics/micro_pages/ {
alias /Users/zhangwenqiang/projects/umu_micro_pages/dist/;
}

location /statics/auth/ {
alias /Users/zhangwenqiang/projects/umu_auth/dist/;
}

location /statics/search/ {
alias /Users/zhangwenqiang/projects/umu_search/dist/;
}
}

2.5 test.devxx.umucdn.cn

test.devxx.umucdn.cntest.m.devxx.umucdn.cn 下配置对应的 SSL 证书即可。

三、问题


3.1 http 自动转换为 https

描述: 之前可能打开过 test.dev15.umucdn.cn , 所以配置好 nginx 之后 test.dev15.umucdn.cn 自动转换成了 https 。所以需要在浏览器的维度来关闭这个功能

解决: 以 Chrome 输入 test.dev15.umucdn.cn 为例

  1. 地址栏输入 chrome://net-internals/#hsts, 打开 Chrome 配置页面

  2. 选择 Domain Security Policy, 在 Query HSTS/PKP domain 中输入 test.dev15.umucdn.cn, 点击 Query

    Preview
  3. 查看返回结果, 如果返回结果不是 Not Found , 返回了一些域名信息,说明 test.dev15.umucdn.cn 已经被强制转换了

  4. Delete domain security policies 中输入 test.dev15.umucdn.cn , 删除该域名的自动转换功能

  5. 新开浏览器 Tab 栏, 地址栏输入 chrome://settings/privacy , 点击清除浏览器数据, 清除范围尽可能的大一些。

  6. 再次选择Domain Security Policy, 在 Query HSTS/PKP domain 中输入 test.dev15.umucdn.cn, 点击 Query 查看返回结果,此时结果为not found则禁止转换https成功