| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- # =============================================================================
- # vasen-website nginx 配置(精简版,仅含 vasen-website 相关路由)
- #
- # 本配置从生产环境的 file-upload.conf 中裁剪,去除了 file-upload/eye-demo/
- # buffett/gaokao/notes/ocr 等无关业务,仅保留 vasen-website 的完整路由。
- #
- # 部署方式:将本文件内容合并到你的 nginx server 块中(需 listen ssl + 证书)。
- # 若作为独立 server,补上 listen/server_name/ssl 配置(见下方注释)。
- # =============================================================================
- # ---- 如需独立 server,取消注释并修改 ----
- # server {
- # listen 8443 ssl;
- # server_name your-domain.com;
- # ssl_certificate /path/to/cert.pem;
- # ssl_certificate_key /path/to/key.pem;
- # ssl_protocols TLSv1.2 TLSv1.3;
- # ssl_ciphers HIGH:!aNULL:!MD5;
- # ---- vasen-website 主路由 ----
- # 项目路径(修改为你的实际部署路径)
- # root /lio/projects/vasen-website;
- location /vasen-website/ {
- alias /lio/projects/vasen-website/;
- index index.html;
- # try_files: 优先尝试 $uri.html(线上 PHP 无扩展名路由的本地 fallback),
- # 再试目录,避免同名目录(about/ news/)优先匹配导致 403
- try_files $uri $uri.html $uri/ $uri/index.html =404;
- # ---- water-cology SPA(Vue hash 路由)----
- # 用 ^~ 前缀修饰符,优先级高于正则 location,确保 JS/CSS 也走这里并带 CORS 头
- location ^~ /vasen-website/water-cology/ {
- alias /lio/projects/vasen-website/water-cology/;
- index index.html;
- try_files $uri $uri/ /vasen-website/water-cology/index.html;
- # SPA 用 type=module + crossorigin,所有资源都需要 CORS 头
- add_header Access-Control-Allow-Origin "*" always;
- # JS/CSS 不缓存(便于改写生效;稳定后可改回 30d)
- location ~* \.(js|css)$ {
- add_header Cache-Control "no-cache" always;
- add_header Access-Control-Allow-Origin "*" always;
- }
- location ~* \.(png|jpg|jpeg|gif|svg|ico|woff2?|ttf|eot)$ {
- expires 30d;
- add_header Cache-Control "public";
- add_header Access-Control-Allow-Origin "*" always;
- }
- # HTML 不缓存
- location ~* \.html$ {
- add_header Access-Control-Allow-Origin "*" always;
- add_header Cache-Control "no-cache";
- }
- # SPA API mock: prod-api/xxx -> prod-api/xxx/index.json
- location /vasen-website/water-cology/prod-api/ {
- alias /lio/projects/vasen-website/water-cology/prod-api/;
- default_type application/json;
- add_header Access-Control-Allow-Origin "*" always;
- add_header Cache-Control "no-cache";
- try_files $uri $uri/index.json =404;
- }
- }
- # ---- Ajax 接口 mock(由 vasen-sync stage04 生成)----
- # HTML 片段接口:/ajax/xxx/N -> web/api/xxx/N.html
- # 匹配任意层级路径下的 /ajax/(页面可能在 product/product_info/ 等子目录)
- # 参数段支持 数字/数字 形式(如 product_more/68/1),取第一段作为文件名
- location ~ ^/vasen-website/.*/ajax/([a-z0-9_]+)/([0-9]+)(?:/[0-9]+)?$ {
- default_type text/html;
- charset utf-8;
- add_header Cache-Control "no-cache";
- root /lio/projects/vasen-website/web/api;
- try_files /$1/$2.html /$1/default.html =204;
- access_log off;
- }
- location ~ ^/vasen-website/.*/ajax/([a-z0-9_]+)/?$ {
- default_type text/html;
- charset utf-8;
- add_header Cache-Control "no-cache";
- root /lio/projects/vasen-website/web/api;
- try_files /$1/default.html =204;
- access_log off;
- }
- # 兼容根路径 /ajax/xxx/N
- location ~ ^/vasen-website/ajax/([a-z0-9_]+)/([0-9]+)(?:/[0-9]+)?$ {
- default_type text/html;
- charset utf-8;
- add_header Cache-Control "no-cache";
- root /lio/projects/vasen-website/web/api;
- try_files /$1/$2.html /$1/default.html =204;
- access_log off;
- }
- location ~ ^/vasen-website/ajax/([a-z0-9_]+)/?$ {
- default_type text/html;
- charset utf-8;
- add_header Cache-Control "no-cache";
- root /lio/projects/vasen-website/web/api;
- try_files /$1/default.html =204;
- access_log off;
- }
- # /web/index.php/butler/download(高频,626处引用)-> 直接服务本地下载页
- location = /vasen-website/web/index.php/butler/download {
- root /lio/projects/vasen-website;
- try_files /butler/download.html =404;
- access_log off;
- }
- # 表单提交接口:返回成功 JSON
- location ~ ^/vasen-website/(product_search|feedback/sendpost|dealer/change_resion)$ {
- default_type application/json;
- add_header Cache-Control "no-cache";
- root /lio/projects/vasen-website/web/api;
- try_files /product_search/success.json /default_success.json =204;
- access_log off;
- }
- # 验证码图片
- location ~ ^/vasen-website/(feedback/captcha|create_code)$ {
- default_type image/png;
- root /lio/projects/vasen-website/web/api;
- try_files /captcha/captcha.png =204;
- access_log off;
- }
- # HTML 不缓存,便于修改即时生效
- location ~* \.html?$ {
- add_header Cache-Control "no-cache, must-revalidate";
- expires off;
- }
- # 静态资源长缓存
- location ~* \.(js|css|svg|ico|png|jpg|jpeg|gif|woff2?|ttf|eot|pdf)$ {
- expires 30d;
- add_header Cache-Control "public";
- access_log off;
- }
- }
- # 根路径无尾斜杠 -> 跳转带斜杠
- location = /vasen-website {
- return 301 /vasen-website/;
- }
- # ---- 如需独立 server,取消注释 ----
- # }
|