Ngnix1.13.3 installation configuration

Nginx download: https://pan.baidu.com/s/1BzdzdKDr179FNOVaifWAgw

Pcre download: https://pan.baidu.com/s/1aVbo8f-87XceLeWou-Q_lw

 

1) Download Nginx and Pcre and upload them to the server /usr/local/src directory

2) Installation script:

cd /usr/local/src
unzip nginx.zip;
rm -rf nginx.zip;
unzip pcre-8.40.zip
cd pcre-8.40
./configure --prefix=/usr/local/pcre
make
make install
cd ../
tar -xvzf nginx-1.13.5.tar.gz
cd nginx-1.13.5
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/src/pcre-8.40

make
make install
ls

 After the installation is complete, start ./nginx

 Note: --with-pcre=/usr/local/src/pcre-8.40 is the source directory.

After installing nginx, we pre-configure the tomcat service proxy:

vi /usr/local/nginx/config/nginx.conf , replace the content with the following:

#user  nobody;
worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  10240;
}


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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

    client_max_body_size 100M;
    client_body_buffer_size 1024k;

    include loadbalancing.conf;
}

:wq! Save and exit. Then create a new loadbalancing.conf in the same directory

vi loadbalancing.conf, copy the following: 

# load balancing configuration

map $zone $loadbalancing
{
	MasterSp  	server1;
	UserQuery	server1;
	CpQuery		server1;
	adimage		server1;
	pincheService	server2;
}
 

upstream server1
{  
	server 127.0.0.1:8081;
	server 127.0.0.1:8082;
	 
	#Each request is allocated according to the hash result of the access ip, so that each visitor can access a back-end server fixedly, which can solve the problem of session.
	ip_hash;
	
	#Allocate requests according to the response time of the back-end server, and assign priority to those with short response time.
	#fair;
}  

 
proxy_cache_path /home/ncache levels=1:2 keys_zone=ncache:20m max_size=50g inactive=30d;

server
{
	listen       80;
	server_name  test.com;
	charset utf-8;
	proxy_ignore_client_abort on;
	error_page   500 502 503 504  /50x.html;
        location = /50x.html {
		root   html;
        }

 	location = /favicon.ico {
		root   html;
	}
	
        #websocket access configuration
	location ~ /ws{
		proxy_pass http://127.0.0.1:8083;
        	# WebScoket Support
        	proxy_http_version 1.1;
        	proxy_set_header Upgrade $http_upgrade;
        	proxy_set_header Connection "upgrade";

        	proxy_set_header X-Forwarded-Host $host;
       		proxy_set_header X-Forwarded-Server $host;
        	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
	 
	#Access with command word address
	location ~ /
	{  
	    proxy_pass_header Server;  
	    proxy_set_header Host $http_host;  
	    proxy_redirect off;  
	    proxy_set_header X-Real-IP $remote_addr;  
	    proxy_set_header X-Scheme $scheme;
	    proxy_set_header X-Frame-Options SAMEORIGIN;
	    proxy_connect_timeout 1800;   	
	    proxy_read_timeout 1800;
	    proxy_send_timeout 1800;
	    if ( $request_uri ~ ^/(\w*) ) {  
                set $zone $1;  
                proxy_pass http://$loadbalancing;  
            }             
        }

	location = /
	{  
		proxy_pass_header Server;  
		proxy_set_header Host $http_host;  
		proxy_redirect off;  
		proxy_set_header X-Real-IP $remote_addr;  
		proxy_set_header X-Scheme $scheme;
		proxy_connect_timeout 1800;    
		proxy_read_timeout 1800;
		proxy_send_timeout 1800;
		set $zone $request_uri;  
		proxy_pass http://$loadbalancing;           
	}
	
	#Static pages
	location ^~ /test/
	{
	    root /home/project/web; #test static resource folder is placed in this directory
	}
	 
}
Pay attention to modify the platform access ip and port under the upstream server1 node and restart ngnix /usr/local/nginx/bin/./nginx -s reload

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326072182&siteId=291194637