If you want a VPS to serve as the frontend of another VPS, you must add a domain name to the front-end VPS for reverse proxy, if you add a backend VPS Domain Name one by one as the frontend VPS, this is especially troublesome. Can you enable it to automatically reverse proxy the backend VPS? You can easily implement it using proxy_pass and $ host.
The following example uses lnmp as the installation environment for ease of use.
Modify the nginx. conf file of the front-end VPS to the following:
Modify the following together.
Location/. (gif | jpg | jpeg | png | bmp | swf) $
{
Expires 30d;
}
In this way, the frontend VPS can reverse proxy any domain name to the backend VPS, as long as the domain name is resolved to the frontend VPS, the backend VPS for domain name binding, then you can directly access
Configuration of one nginx with multiple domain names and multiple tomcatNginx multi-domain configurationWhen you bind multiple domain names to nginx, you can write multiple domain name rules into one configuration file. You can also create multiple domain name configuration files for ease of management, each domain name creates a file, and some similar domain names can also be written in a general configuration file.
1. One file for each domain name
OpenThe directory where the nginx domain name configuration file is stored:/usr/local/nginx/conf/servers. to bind a domain name www.web126.com, create a file: www.web126.com. conf and then write rules in this file, such:
Server
{
Listen 80;
Server_namewww.web126.com; # bind a domain name
Index index.htm index.html index. php; # default file
Root/home/www/web126.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
}
Then restart the nginx server, and the domain name is successfully bound.
Nginx server restart command:/etc/init. d/nginx restart
2. Writing multiple domain names in one file
The same applies to the rules for adding multiple domain names to a file. You only need to write down the previous single domain name repeatedly, for example:
Server
{
Listen 80;
Server_namewww.web126.com; # bind a domain name
Index index.htm index.html index. php; # default file
Root/home/www/web126.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
}
Server
{
Listen 80;
Server_namemsn.web126.com; # bind a domain name
Index index.htm index.html index. php; # default file
Root/home/www/msn.web126.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
}
3. Add 301 redirection for domain names without www
If you want to add a 301 jump to a domain name without www, it is the same as binding a domain name. First, bind a domain name without www. Instead of writing a website directory, you can perform a 301 jump, for example:
Server
{
Listen 80;
Server_name web126.com;
Rewrite ^/(. *) http://www.web126.com/#1 permanent;
}
4. Add 404 web pages
To add 404 web pages, you can add them directly in the page, for example:
Server
{
Listen 80;
Server_namewww.web126.com; # bind a domain name
Index index.htm index.html index. php; # default file
Root/home/www/web126.com; # website root directory
Include location. conf; # Call other rules, which can also be removed
Error_page 404/404 .html;
}
Finally, you need to note that you may need to disable the IP address to directly access port 80 or prohibit the domain name not on this site from binding our IP address. In this case, we should
Put it on the first server as follows:
Server {
Listen 80 default;
Server_name _;
Return 403;
}
After learning the above four rules and methods, you can solve the problem of nginx multi-domain configuration independently.