1. 程式人生 > 其它 >nginx反向代理、負載均衡

nginx反向代理、負載均衡

Nginxp反向及負載均衡_安裝及配置.docx

一、安裝包及下載

  1. 安裝包清單

  1. 下載地址

(1)nginx元件

http://nginx.org/download/nginx-1.15.9.tar.gz

(2) pcre元件

http://nginx.org/download/nginx-1.15.9.tar.gz

(3) zlib元件

http://zlib.net/zlib-1.2.11.tar.gz

(4) openssl元件

https://www.openssl.org/source/openssl-1.0.1t.tar.gz

二、 安裝步驟

(一) 上傳tar包到/usr/local/src目錄下

(二) 安裝OpenSSL

tar –zxvf openssl-1.0.1t.tar.gz

./config & make & make install

(三) 安裝zlib

tar –zxvf zlib-1.2.11.tar.gz

./config & make & make install

(四) 安裝pcre2-10.21

tar –zxvf pcre2-10.21

./config & make & make install

(五) 安裝Nginx

tar –zxvf nginx-1.15.9.tar.gz

#開啟nginx的SSL模組代理https請求用,此步一定要先執行,然後再./config

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

./config

make

make install

三.修改Nginx配置

#user nobody;
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 {
worker_connections 1024;
}


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;

upstream websimp.com {
ip_hash;
server 192.168.169.1:18443;
}

upstream proxysimp.com {
ip_hash;
server 192.168.169.2:8666;
}

upstream simp.com {
ip_hash;
server 192.168.169.3:18443;
}

server {
listen 8666 ssl;
server_name proxysimp.com;

ssl_certificate /usr/local/nginx/ssl/server.pem;
ssl_certificate_key /usr/local/nginx/ssl/privkey.pem;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

#access_log logs/host.access.log main;

location ~ .*\.(js|css|jpg|jpeg|gif|png|ico|pdf|txt|svg)$ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials: true;
proxy_pass https://simp.com/nopermisson;
}

location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials: true;
proxy_pass https://simp.com/nopermisson;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
server {
listen 18443 ssl;
server_name websimp.com;

ssl_certificate /usr/local/nginx/ssl/server.pem;
ssl_certificate_key /usr/local/nginx/ssl/privkey.pem;

ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;

ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;

location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Credentials: true;
proxy_pass https://proxysimp.com/;
}
}

}

一直地一直地往前走。。。執著地勇敢地不回頭,別停留等待