58 lines
1.4 KiB
Nginx Configuration File
58 lines
1.4 KiB
Nginx Configuration File
|
|
# ================================================
|
||
|
|
# 前端应用 Nginx 配置(单页应用)
|
||
|
|
# ================================================
|
||
|
|
|
||
|
|
user nginx;
|
||
|
|
worker_processes auto;
|
||
|
|
error_log /var/log/nginx/error.log warn;
|
||
|
|
pid /var/run/nginx.pid;
|
||
|
|
|
||
|
|
events {
|
||
|
|
worker_connections 1024;
|
||
|
|
}
|
||
|
|
|
||
|
|
http {
|
||
|
|
include /etc/nginx/mime.types;
|
||
|
|
default_type application/octet-stream;
|
||
|
|
|
||
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||
|
|
'$status $body_bytes_sent "$http_referer" '
|
||
|
|
'"$http_user_agent"';
|
||
|
|
|
||
|
|
access_log /var/log/nginx/access.log main;
|
||
|
|
|
||
|
|
sendfile on;
|
||
|
|
tcp_nopush on;
|
||
|
|
keepalive_timeout 65;
|
||
|
|
|
||
|
|
# Gzip 压缩
|
||
|
|
gzip on;
|
||
|
|
gzip_vary on;
|
||
|
|
gzip_comp_level 6;
|
||
|
|
gzip_types text/plain text/css text/xml application/json application/javascript
|
||
|
|
application/xml application/xml+rss text/javascript;
|
||
|
|
|
||
|
|
server {
|
||
|
|
listen 80;
|
||
|
|
server_name localhost;
|
||
|
|
root /usr/share/nginx/html;
|
||
|
|
index index.html;
|
||
|
|
|
||
|
|
# SPA 路由支持
|
||
|
|
location / {
|
||
|
|
try_files $uri $uri/ /index.html;
|
||
|
|
}
|
||
|
|
|
||
|
|
# 静态资源缓存
|
||
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
|
|
expires 7d;
|
||
|
|
add_header Cache-Control "public, immutable";
|
||
|
|
}
|
||
|
|
|
||
|
|
# 禁止访问隐藏文件
|
||
|
|
location ~ /\. {
|
||
|
|
deny all;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|