Nginx domain jump Configuration

Source: Internet
Author: User

We often access a website. What if we set the mgcrazy.com domain name to automatically jump to www.mgcrazy.com when users access it? I have found a lot of information on the Internet, but none of them can solve the problem! Here are my solutions! For your learning and reference!

First, define mgcrazy.com and www.mgcrazy.com in your domain name management to point to your host IP address. We can use the nslookup command to test: directly enter nslookup mgcrazy.com and nslookup www.mgcrazy.com to have a record pointing to the ip address.

Second, we can configure rewrite Rules in nginx. Open the nginx. conf file and find your server configuration section:

 
 
  1. Server

  2. {

  3. Listen 80;

  4. Server_name www.mgcrazy.com mgcrazy.com;

  5. If ($ host! = 'Www .mgcrazy.com '){

  6. Rewrite ^/(. *) $ http://www.mgcrazy.com/#1 permanent;

  7. }

In this way, you can directly access the www.mgcrazy.com directly redirected to mgcrazy.com. That is, let the domain name without www jump to the domain name with www.

3. We can redirect multiple second-level domain names and third-level domain names at will, or let them all jump to the chinaapp.sinaapp.com domain name. Just add the following statement:

 
 
  1. Server

  2. {

  3. Listen 80;

  4. Server_name blog.mgcrazy.com wgkgood.gicp.net;

  5. If ($ host = 'wgkgood .gicp.net '){

  6. Rewrite ^/(. *) $ http://chinaapp.sinaapp.com/#1 permanent;

  7. }

Redirect another free second-level domain name wgkgood.gicp.net to my blog http://chinaapp.sinaapp.com;

This will not affect the search engine after the second-level domain name is abandoned. Seo is very helpful.

For more nginx rules, join us! Mutual Improvement! I always believe that the value of a person is not what he has achieved, but what he has contributed to others!


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.