惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
Tailwind CSS Blog
J
Java Code Geeks
宝玉的分享
宝玉的分享
Jina AI
Jina AI
B
Blog
N
Netflix TechBlog - Medium
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
腾讯CDC
C
Check Point Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
罗磊的独立博客
B
Blog RSS Feed
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 叶小钗
M
MIT News - Artificial intelligence
GbyAI
GbyAI

Ittavern.com

Wimage - Hosting Open-Source Image Uploader with Podman and external S3 Storage Switching from Hugo to picopaper Encryption using SSH Keys with age in Linux ETag in nginx - Simple Resource Caching Sending nginx Logs to Loki with Grafana Alloy How to: Cisco ISE backup to SFTP repository with public key authentication Dummy IP & MAC Addresses for Documentation & Sanitization Deploying ISSO Commenting System for Static Content using Docker Generate a Vanity v3 Hidden Service Onion Address with mkp224o ssh-audit Primer - Audit your SSH Server mtr - More Detailed Traceroute - Network Troubleshooting My Personal Backup Strategy - August 2024 iperf3 - User Authentication with Password and RSA Public Keypair Adding a trash can to Linux with trash-cli Bandwidth Measurement using netcat on Linux Getting started with rsync - Comprehensive Guide Cron Jobs on Linux - Comprehensive Guide with Examples SSH Server Hardening Guide v2 Port Knocking with knockd and Linux - Server Hardening Getting started with rclone - Data transmission Getting started with dig - DNS troubleshooting Getting started with Fail2Ban on Linux Getting started with netcat on Linux with examples URL explained - The Fundamentals Troubleshooting Asking The Right Questions Create tmux layouts using bash scripts Getting started with tcpdump - Ittavern.com Curl on Linux - Reference Guide Getting started with nmap scripts My Offsite Backup - March 2023
Nginx - simple permanent or temporary redirects
2022-11-23 · via Ittavern.com

Temporary or permanent redirect #

First you have to decide whether the redirect will be permanent (301), or just temporary (302). If you are uncertain, just pick temporary and switch later.

Use cases from my understanding:

Permanent 301 redirects:
switching to another domain
merging multiple domains
switching from HTTP to HTTPs
better SEO experience
Temporary 302 redirect:
testing (A/B testing, etc)
single redirects to another domain
redirect to a maintenance page
redirect traffic for load balancing

Both do the same, but still have their use cases. Switching them up could cause problems with various indexes of search engines, SEO, wrongly being flagged as a spammer, and so on.

Simple redirects in nginx #

For this example, I am going to use temporary 302 redirects.

Simple redirect of a sub-domain to a single URL #

server {
    listen      80;
    listen      443;
    server_name  test2.brrl.net;
    location / {
          return 302 https://www.youtube.com/watch?v=dQw4w9WgXcQ;
    }
}

That is a simple redirect of the root of the sub-domain. Try it out: https://test2.brrl.net.

If you want to create a redirection of a subdirectory like /status, simply change it accordingly:

server {
    listen      80;
    listen      443;
    server_name  brrl.net;
    location /status {
          return 302 https://status.brrl.net/status/overview;
    }
}

With this config block, only the subdirectory /status would be redirected. For example: https://brrl.net/status redirects to https://status.brrl.net/status/overview.

other redirects #

There are many more forms of redirects, but I am familiar enough to write about that. I might add more redirects later on, but I'll have to test beforehand.