Skip to content
Discussion options

You must be logged in to vote

For a client-rendered SPA hosted at /, build it with npm run build, then serve the contents of dist as static files:

server {
    listen 80;
    server_name example.com;
    root /var/www/my-app/dist;
    index index.html;

    location /assets/ {
        try_files $uri =404;
    }
    location / {
        try_files $uri $uri/ /index.html;
    }
}

The fallback allows refreshing client-side routes. Replace the hostname/path and configure HTTPS for production. If you host under /app/, align Vite's base, the router basename and nginx's path mapping. An SSR application needs its server runtime instead of this SPA-only configuration. vite preview is for local preview, not a production server.

R…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by amgowda42
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
⌂ 换网址