1. Environment
Operating System: CentOS, RedHat
IP Address: 192.168.209.121
2. Download the software package
yum install -y gcc gcc-c++ autoconf wget yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* yum install pcre* yum install openssl* cd /usr/local/src Nginx: wget http://www.nginx.org/download/nginx-1.9.3.tar.gz Nginx cache purge module (optional): wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
3. Edit and install
tar -zxvf nginx-1.9.3.tar.gz tar -zxvf ngx_cache_purge-2.3.tar.gz cd nginx-1.9.3 ./configure --prefix=/usr/local/nginx-1.9.3 --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=/usr/local/src/ngx_cache_purge-2.3 make make install
4. Kernel parameter optimization
# vim /etc/sysctl.conf Add the following configuration net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 1800 net.ipv4.ip_conntrack_max = 16777216 # If the default parameters are used, network packet loss is prone to occur net.ipv4.netfilter.ip_conntrack_max = 16777216 # If the default parameters are used, network packet loss is prone to occur net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.ip_local_port_range = 1024 65535Configuration takes effect
# sysctl –pModify the iptables startup script and add it to the star() function
# vim /etc/init.d/iptables /sbin/sysctl -p
5. Configure the sample site site
No.Domain Name
Directory
1
www.heytool.com
/www/html/www.heytool.com
2
bbs.heytool.com
/www/html/bbs.heytool.com
6. Modify the nginx configuration file
vim nginx.conf user nobody nobody; # The group and owner of running nginx worker_processes 2; # Start two nginx worker processes, generally write a few CPU cores error_log logs/error.log notice; # error log path pid logs/nginx.pid; # pid 路径 events { worker_connections 1024; # A process can handle 1024 requests at the same time } http { include mime.types; default_type application/octet-stream; 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 logs/access.log main; # Default access log path sendfile on; keepalive_timeout 65; # keepalive timeout # Start to configure a domain name, a server configuration section generally corresponds to a domain name server { listen 80; # # Monitor 80 on all ips of this machine, or it can be written as 192.168.209.121:80, in this case, only monitor port 80 on 192.168.209.121 server_name www.heytool.com; # domain name root /www/html/www.heytool.com; # Site root directory (program directory) index index.html index.htm; # index file location / { # can have multiple locations root /www/html/www.heytool.com; # Site root directory (program directory) } error_page 500 502 503 504 /50x.html; # Define the error page, if it is a 500 error, return 50x.html in the root directory of the site to the user location = /50x.html { root /www/html/www.heytool.com; } } #Start configuring the site bbs.heytool.com server { listen 80; server_name bbs.heytool.com; root /www/html/bbs.heytool.com; index index.html index.htm; # index file location / { root /www/html/bbs.heytool.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /www/html/bbs.heytool.com; } } }
7. Nginx startup and shutdown
# /usr/local/nginx-1.9.3/sbin/nginx //Start nginx # /usr/local/nginx-1.9.3/sbin/nginx –t //Test the accuracy of the nginx configuration file # /usr/local/nginx-1.9.3/sbin/nginx –s reload //Reload nginx # /usr/local/nginx-1.9.3/sbin/nginx –s stop //Close nginx
8. Test
Create a test site# mkdir -p /www/html/www.heytool.com # mkdir -p /www/html/bbs.heytool.com # echo "www.heytool.com" > /www/html/www.heytool.com/index.html # echo "bbs.heytool.com" > /www/html/bbs.heytool.com/index.html
9. Bind hosts and test
Point the two domain names to 192.168.209.121192.168.209.121 www.heytool.com 192.168.209.121 bbs.heytool.com