In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains how to bind nginx reverse proxy secondary domain names. Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to bind nginx reverse proxy secondary domain names"!
1. Application scenarios
We often encounter 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 as ip: ports.
But after all, IP access is inconvenient, not vivid, not easy to remember. Then, we can bind different domain names to each site. Even if we only have one domain name, we can set up multiple secondary domain names, which is easy to implement with nginx.
2. Basic requirements
Usually, online tutorials will post a piece of configuration file code directly, telling us that this is OK. But I find that many beginners who look at tutorial configurations don't succeed like bloggers, so let's talk about the basics.
First of all, I have to have a domain name that I can manage. For example, I have a domain name postmsg.cn, and I can give birth to multiple sub-domain names.
Secondly, there is a public network server that can be accessed. You can set up your own web site on this server. There are two or three or four corresponding ports.
Then, is the domain name and site binding, a radish pit, of course, can also be more than a radish pit...
3. General configuration
There are two places that need to be configured. Let's talk about the first prerequisite first, and it is also a place that some novices easily ignore.
(1) Domain name configuration
The domain name a record resolution points to our public network server, which most people can think of. When parsing, you can only add ip, and you cannot use port number, that is, you can only use the default port 80. (No discussion of domain name forwarding)
If you want to implement subdomain binding, you must configure it properly when domain name resolution. Nginx alone is not enough.
For example, if I want to bind the subdomain p.postmsg.cn to port 8001 of the server, I first need to ensure that requests to access p.postmsg.cn reach the server before nginx can handle them.
At this point, 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, careful), only setting @ and www is definitely not enough.
Figure 1 -Example domain name resolution
(2) Host configuration
After the domain name request arrives at the host, everything can be handed over to nginx for processing.
When modifying nginx configuration, you can modify it directly in the default configuration file (such as/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 how nginx reads configuration files. Our configuration is usually written in http { } block, plus server block, configured in server block. As mentioned earlier, the server block can be written in a separate file, which is included in nginx.conf, and nested include is supported.
Let's look at how the server block is written:
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;}
Here, server_name corresponds to the configured domain name, and proxy_pass corresponds to the real address of the proxy.
(3) Note 1
Be sure to reserve port 80 for nginx responsible for proxies. We can use apache httpd, nginx, tomcat on a server at the same time, but the domain name resolution can only use the default port 80, the comrades in charge of the proxy to get the first-hand request.
(4) Note II
Immediate effectiveness. Some friends feel that their configuration is correct, but also restart the service, can not see the desired results. There are three possible factors.
Domain name resolution takes effect. The minimum effective time of Alibaba Cloud domain name is 10 minutes, and sometimes it may be greater than this value.
Local DNS cache. You can flush the local dns cache using the ipconfig /flushdns command in cmd.
Browser cache. This is probably the least obvious, especially in Google Chrome. After f12, right-click the refresh button next to the address bar in the upper-left corner, click clear cache and hard reload.
The service did not restart. Service nginx restart sometimes does not stop first, and then starts easily.
At this point, I believe that everyone has a deeper understanding of "how to bind nginx reverse proxy secondary domain names", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.