对于搭建nginx集群搭建,请问下统信这服1务1器的操作系统有啥办法?

1.实验物料3个Nginx的实例,其中一个作为反向代理服务器,另外两个作为静态资源Web服务器,还有静态资源nginx-1.18.01个实例 端口80nginx-1.18.02实例 端口分别为 8081 8082静态HTML如下图所示:2.搭建过程1.搭建静态资源Web服务器关于静态资源Web服务器的搭建,我在上一篇博客《Nginx搭建静态资源Web服务器》已经做了详细说明,这里不再说明。现在我就说一下台虚拟机如果启用多个nginx实例。其实启用多个nginx的实例也很简单,只需要多复制几个nginx.conf的配置文件,做少许的修改就可以,然后我们在启动的时候指定不同的nginx.conf配置文件就可以了。我直接copy了两个配置,nginx-8081.conf和nginx-8082.conf放在了config目录下。关于配置文件的具体内容,我直接贴出来:nginx-8081.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;
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/8081.log
main;
sendfile
on;
#tcp_nopush
on;
#keepalive_timeout
0;
keepalive_timeout
65;
gzip
on;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml
text/javascript application/x-httpd-php image/jpeg image/gif image/png;
server {
listen
127.0.0.1:8081;
#server_name
localhost;
#charset koi8-r;
access_log
logs/8081.access.log
main;
location / {
#root
html;
#index
index.html index.htm;
alias /var/html/dreamRoad/;
autoindex on;
set $limit_rate 2m;
}
error_page
500 502 503 504
/50x.html;
location = /50x.html {
root
html;
}
}
}
nginx-8082.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;
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/8082.log
main;
sendfile
on;
#tcp_nopush
on;
#keepalive_timeout
0;
keepalive_timeout
65;
gzip
on;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml
text/javascript application/x-httpd-php image/jpeg image/gif image/png;
server {
listen
127.0.0.1:8082;
#server_name
localhost;
#charset koi8-r;
access_log
logs/8082.access.log
main;
location / {
#root
html;
#index
index.html index.htm;
alias /var/html/dreamRoad/;
autoindex on;
set $limit_rate 2m;
}
error_page
500 502 503 504
/50x.html;
location = /50x.html {
root
html;
}
}
}
2.搭建反向代理服务器配置nginx.conf,配置内容如下:#user
nobody;
worker_processes
1;
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;
keepalive_timeout
65;
gzip
off;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml
text/javascript application/x-httpd-php image/jpeg image/gif image/png;
upstream dream {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
server {
listen
80;
server_name
dream.donkey.com;
access_log
logs/access.log
main;
location / {
proxy_pass
http://dream;
proxy_set_header Host
$host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page
500 502 503 504
/50x.html;
location = /50x.html {
root
html;
}
}
}
如果想配置缓存,可以采用下面的配置:#user
nobody;
worker_processes
1;
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;
keepalive_timeout
65;
proxy_cache_path /tmp/nginxcache levels=1:2 keys_zone=donkey_cache:20m max_size=18m inactive=60m
use_temp_path=on;
gzip
off;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml
text/javascript application/x-httpd-php image/jpeg image/gif image/png;
upstream dream {
server 127.0.0.1:8081;
server 127.0.0.1:8082;
}
server {
listen
80;
server_name
dream.donkey.com;
access_log
logs/access.log
main;
location / {
proxy_cache donkey_cache;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 302 304 10m;
proxy_pass
http://dream;
proxy_set_header Host
$host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page
500 502 503 504
/50x.html;
location = /50x.html {
root
html;
}
}
}
3.启动启动资源服务器
./sbin/nginx -c /usr/local/nginx/conf/nginx-8081.conf
./sbin/nginx -c /usr/local/nginx/conf/nginx-8082.conf
启动代理服务器./sbin/nginx
4.验证利用浏览器访问http://dream.donkey.com/,如下:成功。}

我要回帖

更多关于 nginx集群搭建 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信