45 lines
1.6 KiB
ApacheConf
45 lines
1.6 KiB
ApacheConf
# 宝塔面板Apache配置 - 前后端分离部署
|
|
# 将API请求代理到Node.js后端服务(4001端口)
|
|
# 其他请求服务前端静态文件
|
|
|
|
RewriteEngine On
|
|
|
|
# 代理API请求到后端Node.js服务
|
|
RewriteCond %{REQUEST_URI} ^/api/.*
|
|
RewriteRule ^api/(.*)$ http://127.0.0.1:4001/api/$1 [P,L]
|
|
|
|
# 代理uploads静态资源到后端
|
|
RewriteCond %{REQUEST_URI} ^/uploads/.*
|
|
RewriteRule ^uploads/(.*)$ http://127.0.0.1:4001/uploads/$1 [P,L]
|
|
|
|
# 前端路由处理 - 所有非API和非静态资源请求都指向index.html
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
RewriteCond %{REQUEST_FILENAME} !-d
|
|
RewriteCond %{REQUEST_URI} !^/api/.*
|
|
RewriteCond %{REQUEST_URI} !^/uploads/.*
|
|
RewriteRule ^.*$ /dist/index.html [L]
|
|
|
|
# 设置静态文件缓存
|
|
<IfModule mod_expires.c>
|
|
ExpiresActive On
|
|
ExpiresByType text/css "access plus 1 year"
|
|
ExpiresByType application/javascript "access plus 1 year"
|
|
ExpiresByType image/png "access plus 1 year"
|
|
ExpiresByType image/jpg "access plus 1 year"
|
|
ExpiresByType image/jpeg "access plus 1 year"
|
|
ExpiresByType image/gif "access plus 1 year"
|
|
ExpiresByType image/svg+xml "access plus 1 year"
|
|
</IfModule>
|
|
|
|
# 启用gzip压缩
|
|
<IfModule mod_deflate.c>
|
|
AddOutputFilterByType DEFLATE text/plain
|
|
AddOutputFilterByType DEFLATE text/html
|
|
AddOutputFilterByType DEFLATE text/xml
|
|
AddOutputFilterByType DEFLATE text/css
|
|
AddOutputFilterByType DEFLATE application/xml
|
|
AddOutputFilterByType DEFLATE application/xhtml+xml
|
|
AddOutputFilterByType DEFLATE application/rss+xml
|
|
AddOutputFilterByType DEFLATE application/javascript
|
|
AddOutputFilterByType DEFLATE application/x-javascript
|
|
</IfModule> |