當前的nginx配置如下:
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } location @router{ rewrite ^(.+)$ /index.html last; } }
遇到的問題是,當訪問 http://localhost:80的時候是可以的,但訪問除此之外的其他路由時遇到了502的問題
解決方案:+ try_files
server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ @router; } location @router{ rewrite ^(.+)$ /index.html last; } }
即可