系统环境:RHEL5 [ 2.6.18-8.el5xen ]
软件环境:
nginx-0.7.17
lighttpd-1.4.20.tar.gz
pcre-6.6-1.1
pcre-devel-6.6-1.1
php-5.1.6-5.el5
参考下载地址:
http://sysoev.ru/nginx/nginx-0.7.17.tar.gz (最新稳定版为0.6.32)
http://www.lighttpd.net/download/lighttpd-1.4.20.tar.gz
##########################################################################
一、安装支持软件
1、安装lighttpd以提取spawn-fcgi (如果站点不包含php页面,可以不安装spaw-fcgi、PHP)
shell> tar zxvf lighttpd-1.4.20.tar.gz
shell> cd lighttpd-1.4.20/
shell> ./configure && make
shell> cp -p src/spawn-fcgi
/usr/sbin/spawn-fcgi
2、安装pcre和php(以下软件)
可使用RHEL5自带的rpm包安装,过程略。
二、安装nginx
shell> tar zxvf nginx-0.7.17.tar.gz
shell> cd
nginx-0.7.17/
shell> ./configure –prefix=/opt/nginx
–with-http_stub_status_module –with-http_ssl_module
shell> make
&& make install
shell> ln -sf /opt/nginx/sbin/nginx /usr/sbin/
三、nginx运行控制
1、检查配置文件有无语法错误
shell> nginx -t
2、启动(不带任何参数直接运行即可)
shell> nginx
3、重新加载nginx配置
shell>
killall -s HUP nginx #//或者 killall -1 nginx
4、处理完当前请求后退出nginx
shell>
killall -s QUIT nginx #//或者 killall -3 nginx
四、nginx配置用例
1、常规配置
shell> vi /opt/nginx/conf/nginx.conf
worker_processes 1; #//工作进程数
events {
use epoll; #//增加该事件提高I/O性能
work_connections 4096;
}
http {
include mime.types;
default_types application/octet-stream;
sendfile on;
tcp_nodelay on
keepalive_timeout 60;
server {
listen 80; #//设置监听端口,注意不要和Apache等其他Web程序冲突
server_name www.linux.org;
#//指定使用的主机名
charset utf-8; #//指定站点文件的默认编码
location / {
root html;
#//设置网站根目录
index index.html index.html;
}
error_page 500 502 503 504
/50x.html
location = /50x.html {
root html;
}
}
}
2、添加状态监控
shell> vi /opt/nginx/conf/nginx.conf #//增加以下内容
location ~ ^/NginxStatus/ {
stub_status on;
access_log off;
}
shell> killall -1 nginx
#//使用浏览器访问
http://nginx_server_ip/NginxStatus/
即可看到状态统计页面。(三个数字分别表示:总共处理连接数、成功创建的握手次数、总共处理的请求数)
3、通过FastCGI方式支持PHP语言
1)启动FastCGI服务(用php-cgi做实际处理php页面的程序,用spawn-fcgi是便于同时开启多个php-cgi进程——“-C”选项控制子进程数)
shell>/usr/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi -C 10
2)修改/opt/nginx/conf/nginx.conf配置文件,添加以下内容:
location ~ \.php$ {
root
html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3)重新加载配置
shell> killall -1 nginx
4、虚拟主机设置
修改nginx.conf文件,增加一个server {……}配置即可,每个虚拟主机的参数可以独立配置。
http {
server {
listen 80;
server_name www.vhost1.com;
access_log logs/vhost1.access.log main;
location / {
index
index.html;
root /var/www/vhost1; #//第1个虚拟主机的网页根目录
}
}
server {
listen 80;
server_name www.vhost2.com;
access_log
logs/vhost2.access.log main;
location / {
index index.html;
root
/var/www/vhost2; #//第2个虚拟主机的网页根目录
}
}
}
5、基于反向代理的负载均衡
修改nginx.conf文件,增加upstream配置,指定对应服务器群的IP和权重,并调整server段中的网页根目录配置。使访问nginx服务器的HTTP请求分散到Web群集中的服务器来处理。
http {
upstream my_web_cluster {
server 192.168.2.11:8000 weight=3;
server 192.168.2.12:8000 weight=3;
server 192.168.2.13:8000 weight=3;
server 192.168.2.14:8000 weight=3;
server 192.168.2.15:8000 weight=3;
}
server {
listen 80;
server_name www.domain.com;
location /
{
proxy_pass http://my_web_cluster;
proxy_set_header x-real-IP
$remote_addr;
}
#//注:其他的location配置段(如关于.php文件的)需注释掉,否则可能影响该类文件的重定向。
}
}
分享到:
相关推荐
安装ngix
移动端直播后台,负责接收流,推送流
redis,redis,tomcat集群实例,tomcat-session-jar文件夹下是需要的jar包,启动nginx,redis,tomcat后在浏览器中输入http://localhost/test/test2.jsp进行测试。
Ngix解析与实战测试
ngix + mysql + php 安装包 非常方便而且简洁的绿色安装包,解决了对新手来说复杂的配置
讲解如何使用Ngix做负载均衡服务器的文档,和一些讲解如何使用Ngix的资料
本资源是windows下ngix的环境配置,可以用于rtmp推流。搭配ffmpeg的使用,可将视频文件转化成rtmp网络视频流,并在vlc上进行播放
Nginx选择了epoll和kqueue作为网络I/O模型,在高连接并发的情况下,Nginx是Apache服务器不错的替代品,它能够支持高达50 000个并发连接数的响应,运行稳定,且内存、CPU等系统资源消耗非常低。 ...
在CentOS下安装Ngix服务及集群PHP、Tomcat
很多nextcloud在linux和ngix环境下安装时,提供的单独nextcloud的linux配置文件因为存在空格,导致nextcloud启动失败,这个nextcloud是去空格的配置文件
fastdfs的使用,ngix的单机部署和集群部署,ngix程序包
nginx部署到linuix的详细配置,如果不对自己上百度吧
通过该脚本可以直接安装nginx
解压后有五个文件,atomic,nginx.conf,default.conf,nginx.sh,nginx_cn.zip . 由于nginx它加入GNU计划,所以在安装nginx之前必须要先同意和支持该计划,否则nginx无法安装。atomic上传到/usr/local/src目录下执行...
将Apache配置文件的简单脚本转换为Ngix conf。 安装 $ [sudo] npm install -g apache-to-nginx 用法 参数 $ apache-to-nginx < apache> < nginx> 例子 # generate configuration file with default template ...
vs2013编译 修改nginx.conf中加入rtmp { server { listen 1935; application live { live on; } ...如果运行时缺少libeay32.dll ,ssleay32.dll加上 建立一stop.bat 内容为nginx.exe -s stop 停止服务器
Tool / LibraryUbuntu 16.04.3Commanddos2unixtofrodos_1.7.13+ds-2.debian.tar.xzapt
vs2015编译,添加more_set_head
摘要目前,我们生活中常见的直播系统大多采用流媒体数据逐块推流的设计,并且在服务器端对推流数据进行二次加工处理,此类直播系统的直播延时往往比较高,同时,由于采用了