诸暨公司做网站,西安优秀的集团门户网站建设公司,网站seo诊断方案,html模板制作某俄罗斯小哥#xff0c;竟靠一个服务器软件直接封神#xff1f;
介绍篇
反向代理
正向代理#xff1a;A想要认识C#xff0c;A没有办法直接跟C聊天#xff0c;所以A通过B把消息传给C。 反向代理#xff1a;表面上访问百度都是访问www.baidu.com#xff0c;实际上域名…某俄罗斯小哥竟靠一个服务器软件直接封神
介绍篇
反向代理
正向代理A想要认识CA没有办法直接跟C聊天所以A通过B把消息传给C。 反向代理表面上访问百度都是访问www.baidu.com实际上域名后面有N多具体的ip服务器。 区别是否对代理有感知有就是正向代理没有就是反向代理。
负载均衡
我有一台服务器负载100个请求我新增一台服务器通过负载均衡的配置例如轮训策略每一台服务器承担50个请求这种方式就称为负载均衡。
下载篇
http://nginx.org/en/download.html
Linux
第一步下载安装包
Windows
第一步下载安装包 第二步解压zip文件后文件目录如图所示 第三步启动nginx
输入命令nginx.exe 或 双击 nginx.exe 推荐使用命令行启动否则可能会启动多个nginx 第四步访问 http://localhost/。如果出现以下页面代表启动成功。 命令篇
nginx -s stop
强制关闭
D:\nginx\nginx-1.22.1nginx -s stopD:\nginx\nginx-1.22.1nginx -s stop
nginx: [error] CreateFile() D:\nginx\nginx-1.22.1/logs/nginx.pid failed (2: The system cannot find the file specified)D:\nginx\nginx-1.22.1nginx -s quit
柔和关闭
D:\nginx\nginx-1.22.1nginx -s quitD:\nginx\nginx-1.22.1nginx -s quit
nginx: [error] CreateFile() D:\nginx\nginx-1.22.1/logs/nginx.pid failed (2: The system cannot find the file specified)D:\nginx\nginx-1.22.1
nginx -v
show version and exit
D:\nginx\nginx-1.22.1nginx -v
nginx version: nginx/1.22.1nginx -V
show version and configure options then exit
D:\nginx\nginx-1.22.1nginx -V
nginx version: nginx/1.22.1
built by cl 16.00.30319.01 for 80x86
built with OpenSSL 1.1.1q 5 Jul 2022
TLS SNI support enabled
configure arguments: --with-cccl --builddirobjs.msvc8 --with-debug --prefix --conf-pathconf/nginx.conf --pid-pathlogs/nginx.pid --http-log-pathlogs/access.log --error-log-pathlogs/error.log --sbin-pathnginx.exe --http-client-body-temp-pathtemp/client_body_temp --http-proxy-temp-pathtemp/proxy_temp --http-fastcgi-temp-pathtemp/fastcgi_temp --http-scgi-temp-pathtemp/scgi_temp --http-uwsgi-temp-pathtemp/uwsgi_temp --with-cc-opt-DFD_SETSIZE1024 --with-pcreobjs.msvc8/lib/pcre2-10.39 --with-zlibobjs.msvc8/lib/zlib-1.2.12 --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-mail --with-stream --with-opensslobjs.msvc8/lib/openssl-1.1.1q --with-openssl-optno-asm no-tests -D_WIN32_WINNT0x0501 --with-http_ssl_module --with-mail_ssl_module --with-stream_ssl_modulenginx -s reload
D:\nginx\nginx-1.22.1nginx -s reloadD:\nginx\nginx-1.22.1nginx -s stopD:\nginx\nginx-1.22.1nginx -s reload
nginx: [error] CreateFile() D:\nginx\nginx-1.22.1/logs/nginx.pid failed (2: The system cannot find the file specified)D:\nginx\nginx-1.22.1nginx -s reopen
D:\nginx\nginx-1.22.1nginx -s reopenD:\nginx\nginx-1.22.1nginx -s stopD:\nginx\nginx-1.22.1nginx -s reopen
nginx: [error] CreateFile() D:\nginx\nginx-1.22.1/logs/nginx.pid failed (2: The system cannot find the file specified)D:\nginx\nginx-1.22.1nginx -t
test configuration and exit
D:\nginx\nginx-1.22.1nginx -t
nginx: the configuration file D:\nginx\nginx-1.22.1/conf/nginx.conf syntax is ok
nginx: configuration file D:\nginx\nginx-1.22.1/conf/nginx.conf test is successfulnginx -T
test configuration, dump it and exit
D:\nginx\nginx-1.22.1nginx -T
nginx: the configuration file D:\nginx\nginx-1.22.1/conf/nginx.conf syntax is ok
nginx: configuration file D:\nginx\nginx-1.22.1/conf/nginx.conf test is successful
# configuration file D:\nginx\nginx-1.22.1/conf/nginx.conf:nginx -?
D:\nginx\nginx-1.22.1nginx -?
nginx version: nginx/1.22.1
Usage: nginx [-?hvVtTq] [-s signal] [-p prefix][-e filename] [-c filename] [-g directives]Options:-?,-h : this help-v : show version and exit-V : show version and configure options then exit-t : test configuration and exit-T : test configuration, dump it and exit-q : suppress non-error messages during configuration testing-s signal : send signal to a master process: stop, quit, reopen, reload-p prefix : set prefix path (default: NONE)-e filename : set error log file (default: logs/error.log)-c filename : set configuration file (default: conf/nginx.conf)-g directives : set global directives out of configuration fileD:\nginx\nginx-1.22.1nginx -h
等同于 nginx -?
nginx -c
指定另一个配置文件
D:\nginx\nginx-1.22.1nginx -c conf/nginx2.confTips
正在运行的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;worker_processes 工作进程数默认为1可以根据CPU处理能力适当调大。
events
events {worker_connections 1024;
}worker_connections 每一个worker进程支持的最大连接数量默认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;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;}# 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 Apaches document root# concurs with nginxs 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;# }#}}include mime.types; 默认引入这个文件可以扩展其他文件。default_type application/octet-stream; 默认类型sendfile on;keepalive_timeout 65; 长连接超时时间#gzip on; 请求压缩相当于拿服务器的CPU资源来换请求的大小从而提升网络传输速度。
server
listen 80; nginx默认监听端口server_name localhost; nginx服务名#charset koi8-r;
location
mime.types
文件中的内容
types {text/html html htm shtml;text/css css;text/xml xml;image/gif gif;image/jpeg jpeg jpg;application/javascript js;application/atomxml atom;application/rssxml rss;实战篇
反向代理
1 修改nginx.conf文件来实现代理www.baidu.com location /baidu {proxy_pass https://www.baidu.com/;}当访问 localhost:80/baidu路径的时候nginx已经帮我们反向代理到www.baidu.com域名下。
2 新增server块来代理9001本地服务 代理前
代理后 3 通过80端口代理本地服务9001配置文件新增内容 游览器效果图 4 通过80端口代理内网ip服务效果图
nginx.conf内容
游览器效果图
负载均衡 upstream srv{server 127.0.0.1:8091 weight1;server 127.0.0.1:8092 weight1;}location / {root html;index index.html index.htm;proxy_pass http://srv;}
文章转载自: http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.ranglue.com.gov.cn.ranglue.com http://www.morning.ppllj.cn.gov.cn.ppllj.cn http://www.morning.szoptic.com.gov.cn.szoptic.com http://www.morning.sfwcx.cn.gov.cn.sfwcx.cn http://www.morning.qytpt.cn.gov.cn.qytpt.cn http://www.morning.qnyf.cn.gov.cn.qnyf.cn http://www.morning.zrnph.cn.gov.cn.zrnph.cn http://www.morning.nfcxq.cn.gov.cn.nfcxq.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.bpmnh.cn.gov.cn.bpmnh.cn http://www.morning.mlnbd.cn.gov.cn.mlnbd.cn http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn http://www.morning.bygyd.cn.gov.cn.bygyd.cn http://www.morning.ltdxq.cn.gov.cn.ltdxq.cn http://www.morning.mgwdp.cn.gov.cn.mgwdp.cn http://www.morning.cdrzw.cn.gov.cn.cdrzw.cn http://www.morning.lcbgf.cn.gov.cn.lcbgf.cn http://www.morning.ptqds.cn.gov.cn.ptqds.cn http://www.morning.prgrh.cn.gov.cn.prgrh.cn http://www.morning.xsfny.cn.gov.cn.xsfny.cn http://www.morning.hffjj.cn.gov.cn.hffjj.cn http://www.morning.ptwqf.cn.gov.cn.ptwqf.cn http://www.morning.rpgdd.cn.gov.cn.rpgdd.cn http://www.morning.lzqdd.cn.gov.cn.lzqdd.cn http://www.morning.stwxr.cn.gov.cn.stwxr.cn http://www.morning.xbwqg.cn.gov.cn.xbwqg.cn http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn http://www.morning.wcgcm.cn.gov.cn.wcgcm.cn http://www.morning.nngq.cn.gov.cn.nngq.cn http://www.morning.ghfrb.cn.gov.cn.ghfrb.cn http://www.morning.wpxfk.cn.gov.cn.wpxfk.cn http://www.morning.cbnxq.cn.gov.cn.cbnxq.cn http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn http://www.morning.crsnb.cn.gov.cn.crsnb.cn http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.qlhwy.cn.gov.cn.qlhwy.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.wpsfc.cn.gov.cn.wpsfc.cn http://www.morning.pkdng.cn.gov.cn.pkdng.cn http://www.morning.cdlewan.com.gov.cn.cdlewan.com http://www.morning.ywrt.cn.gov.cn.ywrt.cn http://www.morning.ghrlx.cn.gov.cn.ghrlx.cn http://www.morning.qdxwf.cn.gov.cn.qdxwf.cn http://www.morning.mpnff.cn.gov.cn.mpnff.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.rqjl.cn.gov.cn.rqjl.cn http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.zshuhd015.cn.gov.cn.zshuhd015.cn http://www.morning.xwqxz.cn.gov.cn.xwqxz.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn http://www.morning.pgxjl.cn.gov.cn.pgxjl.cn http://www.morning.ylzdx.cn.gov.cn.ylzdx.cn http://www.morning.zpdjh.cn.gov.cn.zpdjh.cn http://www.morning.wnjwb.cn.gov.cn.wnjwb.cn http://www.morning.qnyf.cn.gov.cn.qnyf.cn http://www.morning.ctfh.cn.gov.cn.ctfh.cn http://www.morning.jjwzk.cn.gov.cn.jjwzk.cn http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.pnmnl.cn.gov.cn.pnmnl.cn http://www.morning.zqmdn.cn.gov.cn.zqmdn.cn http://www.morning.ndcf.cn.gov.cn.ndcf.cn http://www.morning.knlgk.cn.gov.cn.knlgk.cn http://www.morning.lgqdl.cn.gov.cn.lgqdl.cn http://www.morning.bmssj.cn.gov.cn.bmssj.cn http://www.morning.rycd.cn.gov.cn.rycd.cn http://www.morning.glxdk.cn.gov.cn.glxdk.cn http://www.morning.lbgsh.cn.gov.cn.lbgsh.cn http://www.morning.kqcqr.cn.gov.cn.kqcqr.cn http://www.morning.jpkk.cn.gov.cn.jpkk.cn http://www.morning.kkhf.cn.gov.cn.kkhf.cn http://www.morning.nqmhf.cn.gov.cn.nqmhf.cn http://www.morning.rhjhy.cn.gov.cn.rhjhy.cn http://www.morning.ptmsk.cn.gov.cn.ptmsk.cn http://www.morning.pybqq.cn.gov.cn.pybqq.cn http://www.morning.zrgdd.cn.gov.cn.zrgdd.cn http://www.morning.wpxfk.cn.gov.cn.wpxfk.cn http://www.morning.qxmpp.cn.gov.cn.qxmpp.cn http://www.morning.clfct.cn.gov.cn.clfct.cn http://www.morning.khntd.cn.gov.cn.khntd.cn