改下这个配置 server { listen 80; server_name chat.zszhan.cn;

动态 未结 0 7
邮箱用户_r5u2k
邮箱用户_r5u2k LV1 昨天 17:05 发表
摘要:
改下这个配置 server { listen 80; server_name chat.zszhan.cn; #charset koi8-r; #access_log logs/host.access.log main; #proxy_set_header Host $http_host;#不更改请求头信息 gzip on; gzip_disable "msie6"; gzip_static on; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 8 32k; gzip_http_version 1.1; gzip_min_length 1k; gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 由于路由的资源不一定是真实的路径,无法找到具体文件 # 所以需要将请求重写到 index.html 中,然后交给真正的 Vue 路由处理请求资源 #location @router { # rewrite ^.*$ /index.html last; #} location /.well-known/acme-challenge/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU { root /usr/local/bluesky/project/xinzhiai-mj-front/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU; } # SPA 路由重写 location / { try_files $uri $uri/ /index.html; root /usr/local/bluesky/project/xinzhiai-mj-front; index index.html index.htm; # 静态文件缓存策略 if ($request_uri ~* \.(js|css|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$) { add_header Cache-Control "public, max-age=31536000"; # 缓存 1 年 } # 入口文件不缓存 if ($request_uri ~* \.html$) { add_header Cache-Control "no-cache, no-store, must-revalidate"; } } location /ai { rewrite ^(.*) http://$host permanent; } location /poc { rewrite ^(.*) http://$host permanent; } location /npoc { rewrite ^(.*) http://$host permanent; } location /api/chat_message/send { proxy_set_header Host $host; 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; proxy_redirect off; proxy_buffering off; proxy_connect_timeout 300s; # 增加连接超时时间 proxy_read_timeout 300s; # 增加读取超时时间 proxy_pass http://backend/chat_message/send; } location /api/ { # 去掉/api/ rewrite ^/api/(.*)$ /$1 break; proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-R
要确保访问 `http://chat.zszhan.cn/.well-known/acme-challenge/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU` 时直接打开文件 `/usr/local/bluesky/project/xinzhiai-mj-front/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU`,你可以对 Nginx 配置进行以下修改: 1. **确保路径正确**:确保 `root` 指令指向的路径是正确的,并且文件存在。 2. **简化配置**:去掉不必要的 `try_files` 和 `rewrite`,确保直接访问文件。 修改后的配置如下: ```nginx server { listen 80; server_name chat.zszhan.cn; # Gzip 配置 gzip on; gzip_disable "msie6"; gzip_static on; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 8 32k; gzip_http_version 1.1; gzip_min_length 1k; gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; # 直接访问 .well-known/acme-challenge 文件 location /.well-known/acme-challenge/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU { root /usr/local/bluesky/project/xinzhiai-mj-front; try_files $uri =404; } # SPA 路由重写 location / { try_files $uri $uri/ /index.html; root /usr/local/bluesky/project/xinzhiai-mj-front; index index.html index.htm; # 静态文件缓存策略 if ($request_uri ~* \.(js|css|jpg|jpeg|png|gif|ico|svg|woff|woff2|ttf|eot)$) { add_header Cache-Control "public, max-age=31536000"; # 缓存 1 年 } # 入口文件不缓存 if ($request_uri ~* \.html$) { add_header Cache-Control "no-cache, no-store, must-revalidate"; } } # 重定向到根路径 location /ai { rewrite ^(.*) http://$host permanent; } location /poc { rewrite ^(.*) http://$host permanent; } location /npoc { rewrite ^(.*) http://$host permanent; } # API 代理配置 location /api/chat_message/send { proxy_set_header Host $host; 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; proxy_redirect off; proxy_buffering off; proxy_connect_timeout 300s; # 增加连接超时时间 proxy_read_timeout 300s; # 增加读取超时时间 proxy_pass http://backend/chat_message/send; } location /api/ { # 去掉/api/ rewrite ^/api/(.*)$ /$1 break; proxy_pass http://backend; proxy_set_header Host $host; 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; } } ``` ### 关键修改点: 1. **`location /.well-known/acme-challenge/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU`**: - 使用 `root` 指令指向文件所在的根目录。 - 使用 `try_files $uri =404;` 确保直接访问文件,如果文件不存在则返回 404。 2. **简化路径**:去掉不必要的 `rewrite` 和复杂的 `try_files` 逻辑,确保直接访问文件。 ### 测试: 确保文件 `/usr/local/bluesky/project/xinzhiai-mj-front/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU` 存在后,访问 `http://chat.zszhan.cn/.well-known/acme-challenge/FwwaIBpvWhiL6EvInpjkYpixWY0LWWxfhMYmAdC9GhU` 应该能够直接返回文件内容。
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复