In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about the nginx reverse proxy secondary domain name binding methods and points for attention of the sample analysis. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Application scenarios
We often encounter the situation of setting up multiple Web sites on the same server, and it is common practice to configure different ports for different sites so that they can be accessed in the form of IP:Port.
But after all, accessing with IP is not convenient, vivid, and not easy to remember. Then, we can bind a different domain name to each site. (here we will only talk about the public network.) even if we only have one domain name, we can set up multiple second-level domain names, which can be easily achieved using Nginx.
2. Basic requirements
Usually, online tutorials will post a section of configuration file code directly, telling us that this is the Ok. But I find that many beginners look at the tutorial configuration and can't Success like bloggers, so let's talk about the basics.
First of all, it is necessary to have a domain name that I can manage. For example, if I have a domain name of postmsg.cn, I can give birth to multiple sub-domain names.
Secondly, there is a public network server that can be accessed, on which you can set up your own Web site, one or two, three or four, corresponding to different ports.
Then, it is the binding of the domain name and the site, a radish a pit, of course, you can also have more than one radish a pit.
3. General configuration
There are two areas that need to be configured. Let's first talk about the first prerequisites, which are also areas that beginners are easy to overlook.
(1) Domain name configuration
Most people can think of parsing the A record of the domain name to our public network server. You can only add IP when parsing, and you cannot use the port number, that is, you can only use the default port 80. (do not discuss domain name forwarding)
If you want to bind a subdomain name, it must be configured reasonably when resolving the domain name. Otherwise, it is impossible to rely on Nginx alone.
For example, if I want to bind the subdomain p.postmsg.cn to port 8001 of the server, I first need to make sure that the request for access to p.postmsg.cn can reach the server before Nginx can process it.
At this point, you can either add a p host record to the domain name A record resolution, or there is a wildcard * configuration in the host record (* .postmsg.cn access is all resolved to the corresponding server, so use with caution). It is definitely not possible to set @ and www only.
Figure 1-example of domain name resolution
(2) Host configuration
After the request for the domain name arrives at the host, everything can be handed over to Nginx for processing.
When you modify the Nginx configuration, you can modify it directly in the default configuration file (for example, / etc/nginx/nginx.conf, as shown in the following code snippet), or you can create a separate configuration file in a directory, and then include the configuration file in this directory (as shown in line 17).
Http {log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"; access_log / var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048 Include / etc/nginx/mime.types; default_type application/octet-stream; include / etc/nginx/conf.d/*.conf;}
This is the format of the Nginx read configuration file. Our configuration is usually written in the http {} block, plus the server block, and configured in the server block. As I just said, server blocks can be written in a separate file, including that file in nginx.conf, and nested include is supported.
Next, take a look at the writing of the server block:
Server {listen 80; server_name p.postmsg.cn; location / {proxy_pass http://127.0.0.1:8008; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} # access_log logs/p_access.log;}
The server_name here corresponds to the configured domain name, and the proxy_pass corresponds to the real address of the agent.
(3) Note 1
Be sure to leave port 80 to the Nginx in charge of the agent. We can use Apache httpd,Nginx,Tomcat on the same server at the same time, but domain name resolution can only use the default port 80, and the comrades in charge of the agent should get the first-hand request.
(4) Note 2
Immediate effect. Some friends feel that their configuration is correct, but also restart the service, but can not see the desired results. There are three possible factors.
The effective time of domain name resolution. The minimum effective time of Aliyun's domain name is 10 minutes, and sometimes it may be greater than this value.
Local DNS cache. The local DNS cache can be flushed using the ipconfig / flushdns command in CMD.
Browser cache. This is probably the hardest thing to find, especially Google browser. After F12, right-click the refresh button on the edge of the address bar in the upper left corner, click to empty the cache and reload it rigidly.
The service is not restarted. Sometimes service nginx restart may not be as good as stop and then start.
Thank you for reading! On the "nginx reverse proxy secondary domain name binding methods and matters needing attention example analysis" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.