Skip to content
This repository has been archived by the owner on Apr 23, 2019. It is now read-only.

Allow custom rewrite or redirections in nginx #80

Open
michiels opened this issue Aug 7, 2014 · 1 comment
Open

Allow custom rewrite or redirections in nginx #80

michiels opened this issue Aug 7, 2014 · 1 comment

Comments

@michiels
Copy link
Member

michiels commented Aug 7, 2014

We want to figure out a way how we can easily configure redirection statements and what kind of JSON DSL we might want for this.

There is already some work in this PR: #66 which allows people to add virtual servers inside a certain application. In that PR they can be configured to own their own SSL certificates.

In this issue I want to start a short discussion on what we might want to be able to add as custom hosts. We currently use these types in production. This does not mean we need to support them all but we can figure out which ones to begin with:

  • Redirections (or permanent rewrites) (for example for http -> https or www -> no-www)
  • Showing an auto-index file listing (like https://intercityup.com/binaries)
@berkes
Copy link
Collaborator

berkes commented Oct 20, 2014

I am in need for this on two of my servers. Here's my thoughts. This is
how at my previous job at a hosting startup, we had it configured:

  1. A directive in the application configuration to allow generic redirect-domains.
  2. An include directive (as discussed in Allow customization of nginx files #97 ) to include arbitrary files, such as a rewrites.conf to manage more complex rewrite-rules.

This way you can cover 90% of the cases in the application
configuration: redirecting from alternative domains to a canonical,
redirecting www. to non-www or vice-versa and serving the application
over multiple domains (as is possible already, now).

A directive for redirect-domains.

Allowing users to define a list of additional domains that redirect to the main application domain, rather than having the application being served on that domain (and so avoiding e.g. duplicate content issues).
With e.g. the following in the node.json under an application:

  "domain_names": ["example.com", "example.eu"],
  "redirect_domains": ["www.example.com", "www.example.eu", "example.net", "example.org"],

This, then results in the following config:

server {
  listen 80;
  server_name www.example.com www.example.eu example.net example.org;
  return 301 http://example.com$request_uri;
}
server {
   listen 80;
   server_name example.com example.eu;

   passenger_enabled on;
   ... etc..
}

Note that the redirect (return) is to the first in the list of domain_names. We can, after all, redirect to only one place.

Include directive.

Discussed in #97

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants