Last active
November 17, 2022 03:10
-
-
Save ZE3kr/dfe80d881b3665a2631c280bd59d8cc5 to your computer and use it in GitHub Desktop.
Nginx Short Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
# Other configs | |
map $uri $url_short { | |
default /404; | |
/ /; | |
include url.map; | |
} | |
server { | |
# Other configs | |
if ($url_short = /) { | |
# What to do with main page? | |
return 301 https://www.example.com; | |
} | |
if ($url_short = /404) { | |
# How to handle 404? | |
return 404 '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> | |
<html><head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>404 Not Found</title> | |
</head><body style="margin-top: 32px;"> | |
<center><h1>404 Not Found</h1> | |
<p>Sorry! The page you are looking for could not be located</p> | |
<p>Visit the <a href="/">homepage</a></p> | |
</center></body></html> | |
'; | |
} | |
location / { | |
return 301 $url_short; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put all URLs in this file | |
/1 https://example.com; | |
/2 https://example.net; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment