nginx搭建可以再菜鸟教程里面看有详细步骤。http://www.runoob.com/linux/nginx-install-setup.html
或者看下面
一、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
二、首先要安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz(src这里的路径/urs/local/src)下面的src一样
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
2、解压安装包:
[root@bogon src]# tar zxvf pcre-8.35.tar.gz
3、进入安装包目录(可有可无)
[root@bogon src]# cd pcre-8.35
4、编译安装 (编译要进入pcre-8.35)
[root@bogon pcre-8.35]# ./configure [root@bogon pcre-8.35]# make && make install
5、查看pcre版本(可有可无)
[root@bogon pcre-8.35]# pcre-config --version
三,安装 Nginx
1、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.6.2.tar.gz(src跟上面的路径一样)
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
2、解压安装包
[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
3、进入安装包目录
[root@bogon src]# cd nginx-1.6.2
4、编译安装(--add-module=/home/nginx_rtmp/nginx-rtmp-module表示nginx-rtmp-module的解压路径也就是意思加入module,后面的基本一个意思,表示一些文件的)
4.1
[root@bogon home]# mkdir nginx_rtmp 把nginx-rtmp-module放进nginx_rtmp文件,如果是压缩包先解压4.2编译安装
[root@bogon nginx-1.6.2]# ./configure --add-module=/home/nginx_rtmp/nginx-rtmp-module --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 [root@bogon nginx-1.6.2]# make [root@bogon nginx-1.6.2]# make install
5、查看nginx版本
[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v
6,配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容(注意你安装linux系统的时候是几核,两核就把 worker_processes 的1改成2,剩下就可以粘贴复制)
#user nobody;
worker_processes 1;
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#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;
}
rtmp {
server {
listen 1935;
chunk_size 4000;
application hls {
live on;
hls on;
hls_path /home/hls;
hls_fragment 5s;
}
}
}
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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
7,检查配置文件ngnix.conf的正确性命令:(打印出黑色框里面的信息就证明配置正确)
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
8,Nginx 启动命令如下:
8.1启动前需要检查端口是否被占用,如果占用,就杀死占用的进程或者应用或者开启一个新端口。
8.2不是占用就是没有开启端口(下面是开启80端口的命令)
[root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT [root@localhost ]# /etc/init.d/iptables save [root@localhost ]# /etc/init.d/iptables restart8.3启动Nginx
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx
9.验证nginx是否成功 从浏览器访问我们配置的站点ip(也就是系统的ip):
10.使用obs推流,到nginx服务器,通过vcl拉流看直播
下载安装好obs在点击文件-->设置-->流--->流类型(自定义)-->填入(rtmp://192.168.0.*:1935/hls)-->填写流的名字(例如cctv1)-->应用,确认-->都界面开始推流。如果失败有可能是你的系统防火墙影响,关闭防火墙(命令 service iptables stop )!
下载安装好vlc--->点击媒体选择打开网络串流--->输入拉流地址(rtmp://192.168.0.*:1935/hls/cctv1)--->点击播放
11,以下包含了 Nginx 常用的几个命令:
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件 /usr/local/webserver/nginx/sbin/nginx -s reopen # 重启 Nginx /usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
安装时碰到的错误(可以不看)
错误
http request 失败
yum出错Error: Cannot find a valid baseurl for repo: base
解决方法如下(修改dns配置)
vi /etc/resolv.conf
在此文件最后加入:nameserver 8.8.8.8
如果没有vi编辑器可用:
echo "nameserver 8.8.8.8" >>/etc/resolv.conf
然后ping www.baidu.com
可以ping通,不会再出现unknow host
ok,安装依赖,
yum install ld-linux.so.2
最后出现compelete即可
错误
./configure: error: the HTTP rewrite module requires the PCRE library
总结:
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx
make
make install
一切搞定