Published on

Nginx tips

Authors
  • avatar
    Name
    Loc Truong
    Twitter

Trailing slash

Without trailing slash:
location /chatpppeee {
  ...
}
URL: example.com/chatpppeee/users
→ Proxied to: localhost:9000/chatpppeee/users

With trailing slash:
location /chatpppeee/ {
  ...
}
URL: example.com/chatpppeee/users
→ Proxied to: localhost:9000/users

The trailing slash matters because:

  • Path Stripping: With trailing slash, Nginx strips the location prefix from the URI before forwarding
  • URI Consistency: Helps maintain clean URLs in your FastAPI application (you don't need to handle the /chatpppeee prefix in your routes)
  • Avoiding Double Paths: Prevents issues where you might accidentally have the path twice in the URL Without the trailing slash, you would need to either:
  • Include /chatpppeee in all your application routes, or
  • Configure your application to use a root path prefix