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/;
}
}

}

 

 

posted @ 2021-08-23 10:38  loveUworld  阅读(46)  评论(0)    收藏  举报