单个站点
配置如下
server { listen 80; server_name localhost; location / { root /app; index index.html; try_files $uri $uri/ /index.html; } }
其中:
/app 是网站根目录
部署多个站点
server { listen 80; listen 443 ssl http2; server_name www.demo.com; if ($ssl_protocol = "") { return 301 https://$host$request_uri; } # 前端 location / { root /data/wwwroot/www; index index.html; try_files $uri $uri/ /index.html; } # 后台 location ^~/admin { alias /data/wwwroot/admin; try_files $uri $uri/ /admin/index.html; } # 数据接口 location /api { proxy_pass http://127.0.0.1:5000; } }
参考