Using nginx for acceleration
nginx is generally used as a reverse proxy server. And can proxy to any accessible node.
For example, we found that for a restful api website, the domestic access speed is not good. We can use nginx on an overseas node to accelerate.
First install nginx, and then modify nginx.conf as follows:
user www;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
server_tokens off;
#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;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
proxy_ssl_server_name on;
ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2;
include /etc/nginx/conf.d/*.conf;
}
Among them, map $http \ \ upgrade $connection \ \ upgrade is to support websocket. The proxy_ssl_server_name and ssl_protocols are used to better proxy https sites, and then the specific acceleration agent length is in / etc/nginx/conf.d/*.conf;.
/Write a PROXY.conf in etc/nginx/conf.d /
server {
listen 80;
server_name api2-poloniex-com.example.com;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
location / {
proxy_pass https://api2.poloniex.com;
client_max_body_size 10m;
}
}
server {
listen 80;
server_name poloniex-com.example.com;
location / {
proxy_cookie_domain poloniex-com.example.com poloniex.com;
proxy_cookie_domain poloniex.com poloniex-com.example.com;
proxy_pass https://poloniex.com;
client_max_body_size 10m;
}
}
The first server is the proxy websocket, and Upgrade needs to be set. The second is the restful interface, which can set the cookie.
NGINX caching proxy fails with SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure