84 lines
2.8 KiB
Plaintext
84 lines
2.8 KiB
Plaintext
# 宝塔面板 Nginx 站点配置
|
||
# 请将以下配置添加到你的站点配置中
|
||
|
||
server {
|
||
listen 80;
|
||
server_name uzi1.cn; # 你的域名
|
||
index index.php index.html index.htm default.php default.htm default.html;
|
||
root /www/wwwroot/uzi1.cn; # 修改为你的实际网站根目录路径
|
||
|
||
# SSL配置(如果有SSL证书)
|
||
# listen 443 ssl http2;
|
||
# ssl_certificate /path/to/your/cert.pem;
|
||
# ssl_certificate_key /path/to/your/cert.key;
|
||
|
||
# 安全配置
|
||
add_header X-Frame-Options "SAMEORIGIN";
|
||
add_header X-XSS-Protection "1; mode=block";
|
||
add_header X-Content-Type-Options "nosniff";
|
||
|
||
# 静态资源缓存配置
|
||
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
expires 1y;
|
||
add_header Cache-Control "public, immutable";
|
||
add_header Access-Control-Allow-Origin *;
|
||
try_files $uri =404;
|
||
}
|
||
|
||
# API代理配置 - 解决跨域问题
|
||
location /api/ {
|
||
proxy_pass http://192.140.164.137:18080/;
|
||
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;
|
||
|
||
# CORS头部设置
|
||
add_header Access-Control-Allow-Origin *;
|
||
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
|
||
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
|
||
|
||
# 处理OPTIONS预检请求
|
||
if ($request_method = 'OPTIONS') {
|
||
add_header Access-Control-Allow-Origin *;
|
||
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
|
||
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization';
|
||
add_header Access-Control-Max-Age 1728000;
|
||
add_header Content-Type 'text/plain; charset=utf-8';
|
||
add_header Content-Length 0;
|
||
return 204;
|
||
}
|
||
}
|
||
|
||
# Vue SPA 路由配置 - 关键部分!
|
||
location / {
|
||
try_files $uri $uri/ @fallback;
|
||
}
|
||
|
||
# SPA回退配置
|
||
location @fallback {
|
||
rewrite ^.*$ /index.html last;
|
||
}
|
||
|
||
# 直接指定index.html处理所有404
|
||
error_page 404 /index.html;
|
||
|
||
# 禁止访问的文件类型
|
||
location ~ /\.ht {
|
||
deny all;
|
||
}
|
||
|
||
location ~ /\. {
|
||
deny all;
|
||
}
|
||
|
||
# 宝塔面板默认的安全配置
|
||
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) {
|
||
return 404;
|
||
}
|
||
|
||
# 宝塔面板访问日志
|
||
access_log /www/wwwlogs/uzi1.cn.log;
|
||
error_log /www/wwwlogs/uzi1.cn.error.log;
|
||
}
|