Nginx
Nginx (自由 开放 高性能的 http 服务器 和 反向代理服务器)
三个特点
1反向代理 2负载均衡 3 nginx
正向代理列子:
我们需要访问一些国外的网站 我们通过游览器是没有办法访问的
用FQ进行访问 FQ的方式主要是找到一个可以访问国外网站的代理服务器
我们将请求发送给代理服务器 代理服务器去访问国外的网站 然后将访问到的数据传递给我们
反向代理,主要是用于服务器集群分布式部署的情况下,反向代理隐藏了服务器的信息
2、客户端发送的、Nginx反向代理服务器接收到的请求数量,就是我们说的负载量
请求数量按照一定的规则进行分发到不同的服务器处理的规则,就是一种均衡规则
将服务器接收到的请求按规则分发的过程,称为负载均衡
停止nginx 命令: nginx -s stop 或者 nginx -s quit
nginx是一个功能非常强大的web服务器加反向代理服务器,同时又是邮件服务器等等
-------------------------nginx配置( nginx.conf )说明:---------start----------------
#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 { #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 tomcat_all { #负载均衡配置
server localhost:9111;
}
server { #服务器主机配置
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / { # 路由配置
# root html;
# index index.html index.htm;
#}
#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;
}
rewrite ^/ecvs2-app-web$ / last;
rewrite ^/ecvs2-app-web/(.*) /$1 last;
rewrite ^/ecvs2-api-web/(.*) /$1 last;
rewrite ^/ecvs2-auth-web/(.*) /$1 last;
rewrite ^/ecvs2-supervision-web/(.*) /$1 last;
# tomcat_auth
location /auth/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://tomcat_all/ecvs2-auth-web/auth/;
}
# tomcat_api
location /api/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcat_all/ecvs2-api-web/api/;
}
# tomcat_supervision
location /supervision/ {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcat_all/ecvs2-supervision-web/supervision/;
}
# tomcat_app
location / {
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://tomcat_all/ecvs2-app-web/;
}
# 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_buffers 8 128k;
# 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 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
---------------------------------------end------------------------------------------------