nginx負載均衡

nginx負載均衡

nginxserver01: 192.168.161.130
$ vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch
gpgcheck=0
enabled=1
$ yum makecache
$ yum -y install nginx
$ vi /usr/share/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
########################<h1>cloud1801!</h1>###########################
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/&gt;
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p&gt;
<p><em>Thank you for using nginx.</em></p>
nginxwebserver02: 192.168.161.131
upstream: 192.168.161.129
</body>
</html>
$ vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch
gpgcheck=0
enabled=1
$ yum makecache
$ yum -y install nginx
$ vi /usr/share/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
########################<h1>cloud1802!</h1>###########################
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/&gt;
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p&gt;
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
$ vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
任務:
baseurl=http://nginx.org/packages/centos/7/$basearch
gpgcheck=0
enabled=1
$ yum makecache
$ yum -y install nginx
$ mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
$ vi /etc/nginx/nginx.conf
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
####以下爲增加的內容####
upstream webserver {
#ip_hash; ##會話保持功能
server 192.168.161.130:80; ##weight可以設置權重值
server 192.168.161.131:80;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://webserver;
}
}
####以上爲增加的內容####
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章