• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

Nginx for Newbie: setting up server_name_in_redirect directive

December 18, 2023

Nginx for Newbie: Setting up server_name_in_redirect Directive

Nginx is a popular web server software known for its high performance, scalability, and flexibility. It is widely used to serve static content, reverse proxy, and load balance web applications. One of the essential features of Nginx is its ability to handle multiple domains or virtual hosts on a single server. In this article, we will explore the server_name_in_redirect directive in Nginx and how it can be set up to enhance your server’s functionality.

Understanding server_name_in_redirect Directive

The server_name_in_redirect directive is used to control how Nginx generates redirects when handling requests for different server names or domains. By default, Nginx uses the server_name value specified in the server block to generate redirects. However, in some cases, you may want to use the original request’s server name instead of the server_name value. This is where the server_name_in_redirect directive comes into play.

When the server_name_in_redirect directive is set to on, Nginx will use the original request’s server name in redirects. Conversely, when it is set to off, Nginx will use the server_name value specified in the server block.

Setting up server_name_in_redirect Directive

To set up the server_name_in_redirect directive, you need to locate the server block in your Nginx configuration file. The server block typically contains the server_name directive, which specifies the domain or server name associated with the block. To enable the server_name_in_redirect directive, add the following line within the server block:

server_name_in_redirect on;

Save the configuration file and restart Nginx for the changes to take effect. Now, Nginx will use the original request’s server name in redirects.

Use Cases for server_name_in_redirect Directive

The server_name_in_redirect directive can be particularly useful in various scenarios. Let’s explore a few examples:

Multiple Domains

If you have multiple domains pointing to the same server, you can use the server_name_in_redirect directive to ensure that redirects use the correct domain. This is especially important when handling SSL certificates for different domains.

Load Balancing

When using Nginx as a load balancer, you may have multiple backend servers handling requests for different domains. By enabling the server_name_in_redirect directive, you can ensure that redirects are correctly generated based on the original request’s server name.

Reverse Proxy

In a reverse proxy setup, Nginx acts as an intermediary between clients and backend servers. By using the server_name_in_redirect directive, you can ensure that redirects from the backend servers are correctly passed through to the clients.

Summary

The server_name_in_redirect directive in Nginx allows you to control how redirects are generated when handling requests for different server names or domains. By using the original request’s server name, you can ensure that redirects are accurate and consistent. Whether you have multiple domains, use Nginx as a load balancer, or set up a reverse proxy, the server_name_in_redirect directive can enhance your server’s functionality.

For more information about VPS hosting and to explore our high-performance solutions, visit Server.HK.

Recent Posts

  • US VPS for Asia-Pacific Businesses: When to Choose a US Server Over Hong Kong (2026)
  • How to Configure Nginx Load Balancing on Hong Kong VPS for High-Traffic Sites (2026)
  • How to Migrate Your Website to a Hong Kong VPS: Zero-Downtime Transfer Guide (2026)
  • How to Set Up Redis on Hong Kong VPS: Caching, Queues, and Session Storage (2026)
  • How to Host a Python Flask or Django Application on Hong Kong VPS (2026)

Recent Comments

  1. vibramycin injection on How to Choose the Right Hong Kong VPS Plan: A Buyer’s Guide for 2026
  2. allopurinol for gout on CN2 GIA vs BGP vs CN2 GT: What’s the Real Difference for China Connectivity?
  3. antibiotics online purchase on How to Set Up a WordPress Site on a Hong Kong VPS with aaPanel (Step-by-Step 2026)
  4. linezolid cost oral on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  5. metoprolol generic on Hong Kong VPS vs Japan VPS: Head-to-Head for Asia-Pacific Deployments in 2026

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot