Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Configuration and usage of Nginx load balancing

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the configuration and use of Nginx load balancing". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "the configuration and use of Nginx load balancing".

# For more information on configuration, see:

# * Official English Documentation: http://nginx.org/en/docs/

# * Official Russian Documentation: http://nginx.org/ru/docs/

User root

Worker_processes auto

Error_log / var/log/nginx/error.log

Pid / run/nginx.pid

# Load dynamic modules. See / usr/share/nginx/README.dynamic.

Include / usr/share/nginx/modules/*.conf

Events {

Worker_connections 1024

}

Http {

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 / var/log/nginx/access.log main

Sendfile on

Tcp_nopush on

Tcp_nodelay on

Keepalive_timeout 65

Types_hash_max_size 2048

Include / etc/nginx/mime.types

Default_type application/octet-stream

# Load modular configuration files from the / etc/nginx/conf.d directory.

# See http://nginx.org/en/docs/ngx_core_module.html#include

# for more information.

Include / etc/nginx/conf.d/*.conf

/ the key to load balancing [in http]

Upstream group {

Server 192.168.0.180:80

Server 192.168.0.181:80

}

Server {

Listen 80

Listen [::]: 80 default_server

Server_name _

Root / var/www/html

Index index.php

# Load configuration files for the default server block.

Include / etc/nginx/default.d/*.conf

Location / {

Proxy_pass http://group;// negative balance jump group corresponds to the name after upstream. If you do not use load balancer, you can direct it to the corresponding directory with the following two lines masked.

# root / var/www/html

# index index.php index.html index.htm

}

Location ~\ .php$ {

Root / var/www/html

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

# fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name

Fastcgi_param SCRIPT_FILENAME / var/www/html$fastcgi_script_name

Include fastcgi_params

}

Error_page 404 / 404.html

Location = / 40x.html {

}

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

}

}

# Settings for a TLS enabled server.

#

# server {

# listen 443 ssl http2 default_server

# listen [::]: 443 ssl http2 default_server

# server_name _

# root / usr/share/nginx/html

#

# ssl_certificate "/ etc/pki/nginx/server.crt"

# ssl_certificate_key "/ etc/pki/nginx/private/server.key"

# ssl_session_cache shared:SSL:1m

# ssl_session_timeout 10m

# ssl_ciphers HIGH:!aNULL:!MD5

# ssl_prefer_server_ciphers on

#

# # Load configuration files for the default server block.

# include / etc/nginx/default.d/*.conf

#

# location / {

#}

#

# error_page 404 / 404.html

# location = / 40x.html {

#}

#

# error_page 500 502 503 504 / 50x.html

# location = / 50x.html {

#}

#}

}

At this point, I believe you have a deeper understanding of "the configuration and use of Nginx load balancing". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report