A simple tool to generate nginx server configuration for redirects by a given URL list.
Switch branches/tags
Nothing to show
Clone or download
Joao Paulo
Latest commit 357059d Mar 15, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Remove tabs from file before processing Mar 15, 2018
.gitignore Initial commit Mar 14, 2018
LICENSE Initial commit Mar 14, 2018
README.md Add a better example Mar 14, 2018
index.js Add generator code Mar 14, 2018
package.json Add generator code Mar 14, 2018
sample-file.txt Add a better example Mar 14, 2018

README.md

nginx-redirect-generator

A simple tool to generate nginx server configuration for redirects by a given URL list.

Use case

I had to create an nginx server just to redirect from some old domains to new ones. The list of URLs was big and I couldn't generate a general rule because the path on the target url was different from the source. So I created this to help me out :)

It transforms this:

http://sample-domain.com/test/123123 http://another-domain.com/awe123123
http://sample-domain.com/test/555 http://another-domain.com/aweaw
http://sample-domain.com/test/3 http://another-domain.com/tawe3

http://different-domain.com/test/123123 http://another-domain.com/awe123123
http://different-domain.com/test/4555 http://another-domain.com/aweaw
http://different-domain.com/test123/3 http://another-domain.com/tawe3

Into this:

events {}

http {
  server {
    listen 8080;
    server_name sample-domain.com;
    rewrite ^/test/123123$ http://another-domain.com/awe123123 permanent;
    rewrite ^/test/555$ http://another-domain.com/aweaw permanent;
    rewrite ^/test/(.*)$ http://another-domain.com/path/ permanent;
  }
  server {
    listen 8080;
    server_name different-domain.com;
    rewrite ^/test/123123$ http://another-domain.com/awe123123 permanent;
    rewrite ^/test/4555$ http://another-domain.com/aweaw permanent;
    rewrite ^/test123/3$ http://another-domain.com/tawe3 permanent;
  }
}

How to use

  • Install NodeJS (https://nodejs.org)
  • Clone the repository and open its folder
  • Run npm start <path-to-url-list-file>
  • Done!

TODO

  • Configure if I want code 301 or 302 on my redirects