|
|
@@ -35,15 +35,6 @@ server {
|
|
|
location = / {
|
|
|
rewrite ^/ /course break;
|
|
|
}
|
|
|
- # lua 文件上传接口
|
|
|
- location = /api/upload {
|
|
|
- content_by_lua_file /usr/local/openresty/lua/file_upload.lua;
|
|
|
- }
|
|
|
- # lua 读取json文件
|
|
|
- location /api/json/ {
|
|
|
- content_by_lua_file /usr/local/openresty/lua/query_json.lua;
|
|
|
- }
|
|
|
-
|
|
|
#-------------------------------------------------
|
|
|
# 前端应用
|
|
|
#-------------------------------------------------
|
|
|
@@ -63,90 +54,21 @@ server {
|
|
|
add_header Cache-Control "public, max-age=2592000, immutable";
|
|
|
}
|
|
|
|
|
|
- #-------------------------------------------------
|
|
|
- # OSS 静态目录(带目录索引)
|
|
|
- #-------------------------------------------------
|
|
|
- location ^~ /oss/ {
|
|
|
- alias /opt/oss/;
|
|
|
- index _; # 去掉默认的界面
|
|
|
- autoindex on; # 开启目录索引
|
|
|
- autoindex_exact_size off; # 文件大小人性化显示
|
|
|
- autoindex_localtime on; # 显示本地时间
|
|
|
- charset utf-8;
|
|
|
- expires 30d;
|
|
|
- add_header Cache-Control "public, max-age=2592000, immutable";
|
|
|
- # 如果不做这个配置,点击目录下的txt文件,大部分浏览器默认是直接浏览的。这里通过添加响应头来控制。
|
|
|
- if ($request_filename ~* ^.*?\.(html|txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|conf)$){
|
|
|
- add_header Content-Disposition 'attachment;';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
#-------------------------------------------------
|
|
|
# 课程管理
|
|
|
#-------------------------------------------------
|
|
|
location ^~ /course/ {
|
|
|
- alias /opt/course/;
|
|
|
- index index.html;
|
|
|
-
|
|
|
- # 安全头部配置
|
|
|
- add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
|
|
|
- add_header X-Content-Type-Options nosniff;
|
|
|
- add_header X-XSS-Protection "1; mode=block";
|
|
|
- add_header Referrer-Policy "same-origin";
|
|
|
-
|
|
|
- add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), interest-cohort=()";
|
|
|
- add_header Content-Security-Policy "default-src 'self'; worker-src 'self' blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:; connect-src 'self' https:; font-src 'self' data: https:; frame-ancestors 'self'";
|
|
|
-
|
|
|
- try_files $uri $uri/ /course/index.html;
|
|
|
- }
|
|
|
- location = /course/api/device/status {
|
|
|
+ default_type application/json;
|
|
|
|
|
|
- # 允许所有域名跨域
|
|
|
- add_header 'Access-Control-Allow-Origin' '*';
|
|
|
+ add_header 'Access-Control-Allow-Origin' '*';
|
|
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
|
|
|
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
|
|
|
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
|
|
|
|
|
|
- default_type application/json;
|
|
|
- content_by_lua_file /usr/local/openresty/lua/course_device_status.lua;
|
|
|
- }
|
|
|
- location ^~ /course/api/ {
|
|
|
- default_type application/json;
|
|
|
-
|
|
|
- add_header 'Access-Control-Allow-Origin' '*' always;
|
|
|
- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE' always;
|
|
|
- add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always;
|
|
|
- add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
|
-
|
|
|
# 移除 rewrite,改用 proxy_pass 直接处理
|
|
|
- proxy_pass http://124.222.28.5:7213/;
|
|
|
-
|
|
|
- proxy_set_header Host m1.apifoxmock.com;
|
|
|
- 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;
|
|
|
-
|
|
|
- # 处理代理失败的情况(如404)
|
|
|
- proxy_intercept_errors on;
|
|
|
- error_page 404 = @course_api_fallback;
|
|
|
+ proxy_pass http://127.0.0.1:8082/;
|
|
|
}
|
|
|
|
|
|
- location @course_api_fallback {
|
|
|
- default_type application/json;
|
|
|
- content_by_lua_block {
|
|
|
- local uri = ngx.var.uri
|
|
|
-
|
|
|
- if uri:find("^/course/api/system/dict") then
|
|
|
- -- 字典相关接口
|
|
|
- local dict = require "course_dict"
|
|
|
- dict.handle(uri)
|
|
|
- else
|
|
|
- -- 其他接口走 mock
|
|
|
- local mock_router = require "course_mock"
|
|
|
- mock_router("/course/api")
|
|
|
- end
|
|
|
- }
|
|
|
- }
|
|
|
#-------------------------------------------------
|
|
|
# 健康检查
|
|
|
#-------------------------------------------------
|