安裝
- yum install -y nginx(沒有軟件包需安裝軟件包)
- 安裝軟件包
- 創(chuàng)建文件:vi /etc/yum.repos.d/nginx.repo
- 寫入如下配置:(centos7下)
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/x86_64/ gpgcheck=0 enabled=1
- 再次執(zhí)行 :yum install -y nginx
- 環(huán)境變量配置
vi /etc/profile export NGINX_HOME=/usr/local/nginx export PATH=$PATH:$NGINX_HOME/sbin 重新加載 :source /etc/profile
端口映射
- 執(zhí)行nginx -t 可看到配置文件路徑(/etc/nginx/nginx.conf)
[root@localhost yum.repos.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
- 修改配置文件骂澄,執(zhí)行vi /etc/nginx/nginx.conf厅瞎,在最下面加上:
http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80;#監(jiān)聽端口 server_name 10.10.10.204;#訪問的ip location / { proxy_pass http://10.10.10.204:8080;#轉(zhuǎn)向的ip } } }
- 執(zhí)行nginx -t 檢查配置文件語法
- 重啟nginx 執(zhí)行 nginx -s reload
- 防火墻沒關(guān) 執(zhí)行systemctl status firewalld
- 訪問http://10.10.10.204轉(zhuǎn)向http://10.10.10.204:8080
靜態(tài)資源映射
- 修改nginx配置文件
- 在http{}中加一個(gè)server
server { listen 9090 ; server_name 192.168.25.130; location /ckplayer/ {#資源路徑 root /usr/local/static/ckplayer/; autoindex on; }
- nginx -s reload
- 訪問:http://192.168.25.130:9090/ckplayer/ckplayer.js
error:403 forbidden錯(cuò)誤,檢查一下nginx.conf 文件的上面有一個(gè) usernobody 是不是打開的并且改成user root
error:404 結(jié)合錯(cuò)誤日志查看訪問路徑是否正確
Nginx-rtmp 流媒體服務(wù)器搭建
安裝軟件包
- 安裝gcc編譯器:yum -y install gcc gcc-c++
- yum install -y pcre pcre-devel
PCRE(Perl Compatible Regular Expressions) 是一個(gè)Perl庫,包括 perl 兼容的正則表達(dá)式庫苇经。nginx 的 http 模塊使用 pcre 來解析正則表達(dá)式假哎,所以需要在 linux 上安裝 pcre 庫吝梅,pcre-devel 是使用 pcre 開發(fā)的一個(gè)二次開發(fā)庫员咽。nginx也需要此庫 - yum install -y zlib zlib-devel
zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內(nèi)容進(jìn)行 gzip - yum install -y openssl openssl-devel
OpenSSL 是一個(gè)強(qiáng)大的安全套接字層密碼庫力试,囊括主要的密碼算法徙邻、常用的密鑰和證書封裝管理功能及 SSL 協(xié)議,并提供豐富的應(yīng)用程序供測試或其它目的使用畸裳。nginx 不僅支持 http 協(xié)議缰犁,還支持 https(即在ssl協(xié)議上傳輸http)
安裝nginx和rtmp
- nginx: https://nginx.org/en/download.html tar.gz包
- nginx-rtmp :https://github.com/arut/nginx-rtmp-module
- 解壓安裝:解壓到/usr/local/src/ 目錄下:
- 進(jìn)入nginx包目錄:執(zhí)行
./configure --prefix=/usr/local/src/nginx --add-module=../nginx-rtmp-module-master --with-http_ssl_module
make & make install
- 修nginx配置文件
rtmp { server { listen 1935; chunk_size 4096; application vod { play /opt/video/vod; #視頻路徑 } } } 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 10.10.10.204; location / { proxy_pass http://10.10.10.204:8080; } }}
- 訪問:rtmp://10.10.10.204/vod/wyy.mp4 #wyy.mp4是/opt/video/vod下的視頻文件。