对于已安装好的nginx,需要新增模块,我们可以重新编写安装,
1、先使用 nginx -V 查看原来编译都带了那些参数
nginx -V
查看是否安装了mp4模块的支持,如果没有,就先安装MP4模块
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx_mod_h264_streaming-2.2.7 --user=www --group=www --with-http_stub_status_module --with-ngx_http_upstream --with-http_ssl_module --with-http_spdy_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_mp4_module --add-module=/usr/local/nginx-rtmp-module --with-cc-opt=-I/usr/local/ffmpeg/include --with-ld-opt='-L/usr/local/ffmpeg/lib -Wl,-rpath=/usr/local/ffmpeg/lib'
nginx的配置文件
server
{
listen 8889;
server_name 127.0.0.1;
index index.html index.htm index.php;
root /home/wwwroot/default/demo2;
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
#access_log /home/wwwlogs/access.log access;
}
server
{
listen 8888;
server_name 127.0.0.1;
index index.html index.htm index.php;
root /home/wwwroot/default/demo1;
location ~ .*\.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
#access_log /home/wwwlogs/access.log access;
}
server
{
listen 8881;
server_name 127.0.0.1;
location / {
root html;
index index.html index.htm;
proxy_pass http://linuxidc;
}
}
新增负载均衡配置:
1. 在http节点下,添加upstream节点。
upstream linuxidc {
server 192.168.1.158:8888;
server 192.168.1.158:8889;
}
2. 将server节点下的location节点中的proxy_pass配置为:http:// + upstream名称,即“
http://linuxidc”.
location / {
root html;
index index.html index.htm;
proxy_pass http://linuxidc;
}
到此nginx的负载均衡服务器就架设完成了
http://192.168.1.158:8881/
另外还可以按照权重分:
upstream linuxidc {
server 192.168.1.158:8888 weight=5;
server 192.168.1.158:8889 weight=10;
}
浙公网安备 33010602011771号