nginx负载均衡配置,服务器宕机,自动切换到另一个服务器
系统运维
28 人阅读
|
0 人回复
|
2024-03-29
|
本帖最后由 求知者 于 2024-3-29 23:38 编辑
nginx实现双机部署,一个服务器宕机,自动切换到另一个服务器
nginx.conf配置如下:
- #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;
- client_max_body_size 1000m;
-
- #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 myserviceAPI{
- ip_hash;
- server 192.168.1.2:8011;
- server 192.168.1.3:8011;
- }
-
- server {
- listen 8080 default;
- server_name 192.168.1.1;
-
- if ($http_Host !~* "^(192.168.1.1:8080)$" )
- {
- return 403;
- }
-
- #
- location /service {
- proxy_pass http://myserviceAPI/service;
- proxy_connect_timeout 1;
- add_header Content-Security-Policy: default-src=self;
- add_header X-Xss-Protection: 1;
- add_header X-Xss-Protection: mod=block;
- add_header X-Content-Type-Options: nosniff;
- }
- }
- }
-
-
-
复制代码
|
|
求知的路上,无穷无尽
|
|
|
|