Skip to content

Document self-hosted HTTP servers #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Have trailing slash problems after deploying a static website in production?
This repo explains factually the behavior of:
- [Static Site generators](docs/Static-Site-Generators.md)
- [Hosting Providers](docs/Hosting-Providers.md)
- [Self-hosted HTTP servers](docs/Self-Host.md)

We also suggest some [possible solutions](docs/Solutions.md)

Expand Down
79 changes: 79 additions & 0 deletions docs/Self-Host.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Self-hosted HTTP servers

We will serve the [static](../static) folder using different HTTP servers.

## Apache

### Default settings

The Apache server has the following configuration in `sites-available`:

```apache
<VirtualHost *:80>
ServerName trailing-slash-guide-apache-default.sida-chen.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/static
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
```

**Deployment**: [trailing-slash-guide-apache-default.sida-chen.com](http://trailing-slash-guide-apache-default.sida-chen.com)

| Url | Result |
| ------------------ | ----------- |
| /file | 💢 404 |
| /file/ | 💢 404 |
| /file.html | ✅ |
| /folder | ➡️ /folder/ |
| /folder/ | ✅ |
| /folder/index.html | ✅ |
| /both | ➡️ /both/ |
| /both/ | ✅ |
| /both.html | ✅ |
| /both/index.html | ✅ |

### How do I...

- ...make the `/file` path accessible?

A: Add the following to your configuration:

```apache
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.[A-Za-z0-9]*$|/$)
RewriteRule ^(.*)$ $1.html
```

This appends the `.html` extension to any requests to routes without trailing slash or extension. Check out [trailing-slash-guide-apache-no-extension.sida-chen.com](http://trailing-slash-guide-apache-no-extension.sida-chen.com) for this configuration in action.

| Url | Result |
| ------------------ | ----------- |
| /file | ✅ |
| /file/ | 💢 404 |
| /file.html | ✅ |
| /folder | 💢 404 |
| /folder/ | ✅ |
| /folder/index.html | ✅ |
| /both | ✅ |
| /both/ | ✅ |
| /both.html | ✅ |
| /both/index.html | ✅ |

Note the caveat: the `/folder` path is no longer accessible without an explict trailing slash.

- ...enforce a trailing slash policy?

A: <!-- TODO -->

- ...make all routes accessible?

A: <!-- TODO -->

## Nginx

<!-- TODO -->

## Vercel/serve

This is a simple HTTP server run in Node.js. It has the same configuration options and implementation as [Vercel](./Hosting-Providers.md#Vercel), so read more about it there.
3 changes: 3 additions & 0 deletions static/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script type="module">
import {markdownTable} from "https://cdn.skypack.dev/markdown-table@3.0.0";
Expand Down