Skip to content

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

License

Notifications You must be signed in to change notification settings

jptannus/nginx-redirect-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:https://sample-domain.com/test/123123 http:https://another-domain.com/awe123123
http:https://sample-domain.com/test/555 http:https://another-domain.com/aweaw
http:https://sample-domain.com/test/3 http:https://another-domain.com/tawe3

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

Into this:

events {}

http {
  server {
    listen 8080;
    server_name sample-domain.com;
    rewrite ^/test/123123$ http:https://another-domain.com/awe123123 permanent;
    rewrite ^/test/555$ http:https://another-domain.com/aweaw permanent;
    rewrite ^/test/(.*)$ http:https://another-domain.com/path/ permanent;
  }
  server {
    listen 8080;
    server_name different-domain.com;
    rewrite ^/test/123123$ http:https://another-domain.com/awe123123 permanent;
    rewrite ^/test/4555$ http:https://another-domain.com/aweaw permanent;
    rewrite ^/test123/3$ http:https://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!

Docker image

  • Build docker image with docker build -t nginx-redirect-generator .
  • Create a URL fil list based on the sample-file.txt
  • Run the docker image with docker run --rm nginx-redirect-generator <url-file.txt>

TODO

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published