Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx automatically jumps to with www domain name rule configuration, Nginx multi-domain name jump to primary domain name

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx domain name jump Nginx jump automatically to www domain name rule configuration, what if you set the xxx.org domain name to automatically jump to www.xxx.org when the user accesses it?

1. Define xxx.org and www.xxx.org in your domain name management to point to the ip address of your host. You can use the nslookup command to test

Enter both nslookup xxx.org and nslookup www.xxx.org directly with an A record pointing to ip.

Second, configure rewrite rules in nginx. Open the Nginx.conf file to find the server configuration segment: [the following is my server configuration segment]

# disable IP address access # server {listen 80 default_server; server_name _; return 403;} # prohibit IP address access # server {listen 80; # listen443 ssl; # return 500; server_name www.xxx.org xxx.org If ($host! = 'www.xxx.org') {rewrite ^ / (. *) $http://www.xxx.org/$1 permanent;}}

This is the www.xxx.com where the user directly accesses the xxx.com and directly redirects. That is, let the domain name without www jump to the domain name with www.

III. Expansion

Can be multiple secondary domain names, tertiary domain names can be redirected at will, or let them all jump to the domain name xxx.xxx.com, add the following statement

Server {listen 80; # listen443 ssl; # return 500; server_name xxx.xxx.com xxx.xxx.org; if ($host! = 'xxx.xxx.org') {rewrite ^ / (. *) $http://xxx.xxx.com/$1 permanent;}}

The above allows another secondary domain name, xxx.xxx.org, to jump to xxx.xxx.com.

In this way, it will not affect the search engine after giving up the second-level domain name. Very helpful to seo

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report