Use Nginx to build a virtual host in Linux

Source: Internet
Author: User
Tags imap
& Nbsp; Nginx (enginex) is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by the Rambler.ru site with the highest access volume in Russia as IgorSysoev. it has been running on this site for more than two and a half years. Igor uses the source code as Nginx ("engine x") as a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by the Rambler.ru site with the highest access volume in Russia as Igor Sysoev. it has been running on this site for more than two and a half years. Igor publishes source code in the form of a class BSD license. Despite being a beta version, Nginx is well known for its stability, rich feature sets, sample configuration files, and low system resource consumption.
1. obtain Nginx
 
(1) Official website http://nginx.org/en/download.html
 
(2) official documents http://wiki.nginx.org/
 
(3) Chinese document http://wiki.nginx.org/NginxChs
 
The latest stable version: Nginx 1.0.2)
 
2. install Nginx
 
# Wget http://nginx.org/download/nginx-1.0.2.tar.gz
# Tar zxvf nginx-1.0.2.tar.gz
# Cd nginx-1.0.2
#./Configure
# Make
# Make install is installed in the/usr/local/nginx directory by default. 3. common Nginx commands (1) Start/usr/local/nginx/sbin/nginx (2) stop/usr/local/nginx/sbin/nginx-s stop (3) reload the configuration file (hot restart)/usr/local/nginx/sbin/nginx-s reload (4) check the configuration file/usr/local/nginx/sbin/nginx-t (5)/usr/local/nginx/sbin/nginx-p path, reset the ngix Startup directory (default:/usr/local/nginx/), for example,/usr/local/nginx/sbin/nginx-p/home/nginx (6) /usr/local/nginx/sbin/nginx-c filename, reset the configuration file (default: conf/nginx. conf) for example:/usr/local/nginx/sbin/nginx-c/home/nginx. conf (7) set the startup service on/etc/rc. add nginx startup commands to the local file, such as/usr/local/nginx/sbin/nginx 4. configure the VM (1) open the configuration file usr/local/nginx/conf/nginx. conf, you can see that http contains multiple servers, comment out the default server in the configuration, and add server {
Listen 80;
Charset utf8;
Server_name www.linuxidc.com alias linuxidc.com;
Location /{
Proxy_pass http: // 117.0.0.138: 8881;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_set_header Host $ http_host;
}
}
Server {
Listen 80;
Charset utf8;
Server_name abc.com;
Location /{
Proxy_pass http: // 117.0.0.138: 10010;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_set_header Host $ http_host;
}
} Then the two virtual hosts are configured. One is linuxidcX.com and the other is abc.com.
 
5. configure the cache for the VM, which is equivalent to the Squid service.
 
(1) caching is not suitable for systems with high real-time performance.
 
(2) the configuration is as follows:
 
 
Proxy_cache_path/usr/local/nginx/cache levels = 1:2 keys_zone = STATIC: 10 m
 
Inactive = 24 h max_size = 1g;
 
 
 
Server {
Listen 80;
Charset utf8;
Server_name www.linuxidcX.com alias linuxidc.com;
Location /{
Proxy_pass http: // 117.0.0.138: 8881;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_set_header Host $ http_host; proxy_cache STATIC; # The cache name corresponds to the above keys_zone = STATIC: 10 m
Proxy_cache_valid 200 1d; proxy_cache_use_stale error timeout invalid_header updating
Http_500 http_502 http_503 http_504;
}
}
6. start nginx
 
(1) Run/usr/local/nginx/sbin/nginx to start nginx.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.