Skip to content

Commit f65053c

Browse files
docs: added nginx deployment documentation (#3770)
closes #3235
1 parent 972c100 commit f65053c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

docs/guide/deploy.md

+44
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,47 @@ You can deploy your Vitepress website on [Kinsta](https://kinsta.com/static-site
291291
### Stormkit
292292

293293
You can deploy your VitePress project to [Stormkit](https://www.stormkit.io) by following these [instructions](https://stormkit.io/blog/how-to-deploy-vitepress).
294+
295+
### Nginx
296+
297+
Here is a example of an Nginx server block configuration. This setup includes gzip compression for common text-based assets, rules for serving your VitePress site's static files with proper caching headers as well as handling `cleanUrls: true`.
298+
299+
```nginx
300+
server {
301+
gzip on;
302+
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
303+
304+
listen 80;
305+
server_name _;
306+
index index.html;
307+
308+
location / {
309+
# content location
310+
root /app;
311+
312+
# exact matches -> reverse clean urls -> folders -> not found
313+
try_files $uri $uri.html $uri/ =404;
314+
315+
# non existent pages
316+
error_page 404 /404.html;
317+
318+
# a folder without index.html raises 403 in this setup
319+
error_page 403 /404.html;
320+
321+
# adjust caching headers
322+
# files in the assets folder have hashes filenames
323+
location ~* ^/assets/ {
324+
expires 1y;
325+
add_header Cache-Control "public, immutable";
326+
}
327+
}
328+
}
329+
```
330+
331+
This configuration assumes that your built VitePress site is located in the `/app` directory on your server. Adjust the `root` directive accordingly if your site's files are located elsewhere.
332+
333+
::: warning Do not default to index.html
334+
The try_files resolution must not default to index.html like in other Vue applications. This would result in an invalid page state.
335+
:::
336+
337+
Further information can be found in the [official nginx documentation](https://nginx.org/en/docs/), in these issues [#2837](https://github.com/vuejs/vitepress/discussions/2837), [#3235](https://github.com/vuejs/vitepress/issues/3235) as well as in this [blog post](https://blog.mehdi.cc/articles/vitepress-cleanurls-on-nginx-environment#readings) by Mehdi Merah.

0 commit comments

Comments
 (0)