Debian and Ubuntu both come with Nginx and use them to configure the reverse proxy of Nginx, which is very convenient. Install Nginx and run the following command to install and run Nginxapt-getinstallnginx/etc/init. d/nginxstart. Then access port 80 of the IP address in the browser, and you will see "welcometongstart! ", Which indicates Nginx installation is complete! Configure Nginx for reverse proxy Nginx
Debian and Ubuntu both come with Nginx and use them to configure the reverse proxy of Nginx, which is very convenient.
Install Nginx
Run the following command to install and run Nginx
Apt-get install nginx
/Etc/init. d/nginx start
Then access port 80 of the IP address in the browser and you will see "Welcome to Nginx! ", Which indicates Nginx installation is complete!
Configure Nginx for reverse proxy
The default site configuration file for Nginx is/etc/nginx/sites-available/default. Modify the following parts of this file:
Location /{
Root/var/www/nginx-default;
Index index.html index.htm;
}
To:
Location /{
Proxy_pass http://www.6688.cc /;
Proxy_redirect off;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}
Restart Nginx:
/Etc/init. d/nginx restart
Then re-access port 80 on the IP address in the browser. The google homepage is displayed, and the reverse proxy configuration is successful.
Multi-domain reverse proxy configuration instance
Configure a reverse proxy for multiple domain names on one VPS. For example, we have two domain names: test1.idcfree.com and test2.idcfree.com. We want the user to access test1.idcfree.com to view the content of www.linuxidc.com, if you want to see www.baidu.org.tw when you access test2.idcfree.com, you only know the existence of test1.idcfree.com and test2.idcfree.com, but do not know the existence of www.linuxidc.com and www.baidu.org.tw.
First, you need to direct the domain names test1.idcfree.com and test2.idcfree.com to the vps ip address.
Then add two files in the/etc/nginx/sites-available directory named test1.idcfree.com and test2.idcfree.com.
The content of the test1.idcfree.com file is as follows:
Server {
Listen 80;
Server_name test1.idcfree.com;
Location /{
Proxy_pass http://www.linuxidc.com /;
Proxy_redirect off;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}
}
The content of the file test2.idcfree.com is as follows:
Server {
Listen 80;
Server_name test2.idcfree.com;
Location /{
Proxy_pass http://www.baidu.org.tw /;
Proxy_redirect off;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}
}
Then run the following command:
Cd/etc/nginx/sites-enabled
Ln-sf/etc/nginx/sites-available/test1.idcfree.com. ln-sf/etc/nginx/sites-available/test2.idcfree.com.
/Etc/init. d/nginx restart
When you access test1.idcfree.com in your browser, the content of www.linuxidc.com will appear. When you access test2.idcfree.com, the content of www.baidu.org.tw will appear.
Advanced Configuration of reverse proxy
For some advanced configurations of Nginx reverse proxy, we will continue to write blog introduction, so stay tuned.