Nginx
http://nginx.org/en/download.html
https://www.cnblogs.com/gerry2019/p/11855289.html
关闭IIS 80端口,启动nginx
启动:start nginx.exe
关闭:nginx -s stop
重启:nginx -s reload
退出:nginx -s quit
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
负载均衡:配置upstream dynamic_pools和proxy_pass
dynamic_pools 是名称随便取,跟proxy_pass保持一直
ip_hash注释打开,每个请求按访问的ip和hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session问题。
listen端口不能与iis端口冲突,需设置未使用的端口
-------------------------------------------------------------------------------------
#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 dynamic_pools { #ip_hash; server 10.123.236.123:8081 weight=1; server 10.123.5.229:8081 weight=1; } server { listen 8080; server_name 10.123.5.229; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; proxy_pass http://dynamic_pools; 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 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; # } #} }
将Nginx设置成windows服务
参考:Windows 下将 Nginx 设置成服务 - Code7Rain - 博客园
1.下载Windows Service Wrapper工具,放在nginx.exe目录,修改名称为nginx-service.exe

2.添加nginx-service.exe.config文件:
<configuration> <startup> <supportedRuntime version="v2.0.50727" /> <supportedRuntime version="v4.0" /> </startup> <runtime> <generatePublisherEvidence enabled="false"/> </runtime> </configuration>
3.添加nginx-service.xml文件:
<service> <id>nginx</id> <name>Nginx Service</name> <description>High Performance Nginx Service</description> <logpath>D:\tools\nginx-1.26.3\logs</logpath> <log mode="roll-by-size"> <sizeThreshold>10240</sizeThreshold> <keepFiles>8</keepFiles> </log> <executable>D:\tools\nginx-1.26.3\nginx.exe</executable> <startarguments>-p D:\tools\nginx-1.26.3</startarguments> <stopexecutable>D:\tools\nginx-1.26.3\nginx.exe</stopexecutable> <stoparguments>-p D:\tools\nginx-1.26.3 -s stop</stoparguments> </service>
4.执行安装指令
nginx-service.exe install

浙公网安备 33010602011771号