Ubuntu16.04 编译nginx和nginx-rtmp和rtmp转flv和sub_filter并配置php
这标题真长
以前写过一篇 Ubuntu16.04 如何配置 nginx,当时用的是 apt-get 安装的,现在感觉还是太年轻……
于是乎,nginx 配置备忘录 2.0 版本出现了!
这次用的是编译的方法来安装,并且也顺道编译了一些我常用的模块进去,方便使用
第一步:安装编译所需的各种依赖库:
apt-get update
apt-get install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev
第二步:下载 nginx 并解压
mkdir /home/nginx
cd /home/nginx
wget http://nginx.org/download/nginx-1.15.8.tar.gz
tar -xzvf nginx-1.15.8.tar.gz
选用的是 1.15.8 版本的 nginx,因为他对那个 rtmp 转 flv 的模块支持最好……
第三步:下载其他的模块
git clone https://github.com/mikuily/nginx-rtmp-module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
第四步:编译并安装 nginx
cd nginx-1.15.8
./configure --prefix=/usr/local/nginx --with-http_sub_module --with-http_stub_status_module --with-http_ssl_module --add-module=/home/nginx/nginx-rtmp-module --add-module=/home/nginx/ngx_http_substitutions_filter_module
make
make install
第五步:手动安装服务
拷贝以下内容,保存到 /etc/systemd/system/nginx.service
[Unit]
Description=nginx stable last
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
第六步:安装 php
apt-get install php php-fpm php-mysql
第七步:配置 php
打开 /etc/php/7.0/fpm/pool.d/www.conf
修改第 36 行
listen=127.0.0.1:9000
保存退出
然后用 ps -ef | grep 找到 php 的进程,先用 kill 杀掉然后执行
php-fpm7.0
然后使用
netstat -tlnp
检查 9000 端口是否有被正确使用
第八步:配置 /usr/local/nginx.conf
找到代码块
locaition /
将 index 后面添加上 index.php
并且找到下面这块代码块(默认注释的)
location ~ \.php$ {
root html;
fastcgi_pass *****;
fastcgi_index *****;
***
***
}
(我忘了原来他是怎么配置的因为我把它删了
将 fastcgi_pass 改为
fastcgi_pass 127.0.0.1:9000;
以及将 fastcgi_param 改为
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
rtmp 转 flv 的相关配置可以参考 https://github.com/mikuily/nginx-rtmp-module
第九步:执行
systemctl start nginx
应该就可以啦!
如果出现报错可以用
systemctl status nginx
检查
一般都是配置文件写错,看报错信息里面的行号应该就能很快的找到问题在哪了
这样配置后的网站根目录在
/usr/local/nginx/html
其他 nginx 的扩展用法就是 nginx.conf 里面的东西了
(如果有空就写个 nginx.conf 的解析吧
(又挖坑
(咕
本文链接:https://hatsunemiku-tov.imwork.net/archives/135/
版权声明:本文为原创文章,版权归 T.O.V 所有。所有原创文章采用 知识共享署名-非商业性使用 4.0 国际许可协议 进行许可。
您可以自由的转载和修改,但请务必注明文章来源并且不可用于商业目的。