Advertisement
Guest User

Untitled

a guest
May 9th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.49 KB | None | 0 0
  1. https://habrahabr.ru/post/162237/
  2.  
  3. http://firstwiki.ru/index.php/%D0%94%D0%BE%D0%B1%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BC%D0%BE%D0%B4%D1%83%D0%BB
  4.  
  5. %D0%B5%D0%B9_nginx_%D0%B2_Linux_%28Debian/Ubuntu/CentOS%29
  6.  
  7. https://github.com/sergey-dryabzhinsky/nginx-rtmp-module
  8. https://github.com/mattpepin/nginx-rtmp-module
  9.  
  10. http://nginx.org/download/nginx-1.2.1.tar.gz
  11. -----------------------------------------------------
  12. Ставить этот вариант:
  13. Качаем:
  14. https://github.com/arut/nginx-rtmp-module
  15. https://github.com/arut/nginx-rtmp-module/archive/master.zip
  16.  
  17. Качаем:
  18. Полная версия nginx для ubuntu
  19. http://packages.ubuntu.com/trusty/httpd/nginx-full
  20. http://archive.ubuntu.com/ubuntu/pool/main/n/nginx/nginx_1.4.6.orig.tar.gz
  21. http://archive.ubuntu.com/ubuntu/pool/main/n/nginx/nginx_1.4.6-1ubuntu3.7.debian.tar.gz
  22.  
  23. Распаковаем nginx_1.4.6.orig.tar.gz
  24. Добавляем в папку modules модули из nginx_1.4.6-1ubuntu3.7.debian.tar.gz
  25. Заменяем модуль headers-more-nginx-module скачанным отсюда https://github.com/openresty/headers-more-nginx-module
  26.  
  27. Ставим:
  28. sudo apt-get install nginx nginx-extras
  29.  
  30. Проверяем версию и установленные библиотеки
  31. nginx -V
  32.  
  33. Должно получиться нечто похожее на:
  34. root@UbuntuSRV01:/etc/nginx# nginx -V
  35. nginx version: nginx/1.4.6
  36. built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
  37. TLS SNI support enabled
  38. configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -
  39.  
  40. D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-
  41.  
  42. path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-
  43.  
  44. path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-
  45.  
  46. path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-
  47.  
  48. uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-
  49.  
  50. http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --
  51.  
  52. with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-
  53.  
  54. http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_spdy_module --with-http_sub_module
  55.  
  56. --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/home/firs/nginx-1.4.6/modules/headers-more-nginx-
  57.  
  58. module --add-module=/home/firs/nginx-1.4.6/modules/nginx-auth-pam --add-module=/home/firs/nginx-1.4.6/modules/nginx-cache-purge
  59.  
  60. --add-module=/home/firs/nginx-1.4.6/modules/nginx-dav-ext-module --add-module=/home/firs/nginx-1.4.6/modules/nginx-
  61.  
  62. development-kit --add-module=/home/firs/nginx-1.4.6/modules/nginx-echo --add-module=/home/firs/nginx-1.4.6/modules/ngx-
  63.  
  64. fancyindex --add-module=/home/firs/nginx-1.4.6/modules/nginx-http-push --add-module=/home/firs/nginx-1.4.6/modules/nginx-lua
  65.  
  66. --add-module=/home/firs/nginx-1.4.6/modules/nginx-upload-progress --add-module=/home/firs/nginx-1.4.6/modules/nginx-upstream-
  67.  
  68. fair --add-module=/home/firs/nginx-1.4.6/modules/ngx_http_substitutions_filter_module --add-module=/home/firs/nginx-rtmp-
  69.  
  70. module-master
  71.  
  72.  
  73. Сохраним вывод команды nginx -V в какой-нибудь текстовый редактор - эта информация нам пригодится при конфигурировании. Видим,
  74.  
  75. что версия nginx у нас установлена 1.2.1 - скачиваем такую же версию:
  76. # wget http://nginx.org/download/nginx-1.2.1.tar.gz
  77.  
  78. Распакуем архив и перейдём в папку nginx-1.2.1:
  79. # tar –xvf nginx-1.2.1.tar.gz
  80. # cd nginx-1.2.1
  81.  
  82. Далее, для сборки, нам потребуется установить в систему дополнительные пакеты.
  83. Для Debian/Ubuntu выполняем:
  84. # aptitude install build-essential
  85.  
  86. Конфигурируем
  87. ./configure --add-module=/path/to/nginx-rtmp-module
  88. При конфигурации указываем полные пути до модулей, например:
  89. ./configure --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -
  90.  
  91. D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-
  92.  
  93. path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-
  94.  
  95. path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-
  96.  
  97. path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-
  98.  
  99. uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-
  100.  
  101. http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_flv_module --
  102.  
  103. with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_mp4_module --with-
  104.  
  105. http_perl_module --with-http_random_index_module --with-http_secure_link_module --with-http_spdy_module --with-http_sub_module
  106.  
  107. --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/home/firs/nginx-1.4.6/modules/headers-more-nginx-
  108.  
  109. module --add-module=/home/firs/nginx-1.4.6/modules/nginx-auth-pam --add-module=/home/firs/nginx-1.4.6/modules/nginx-cache-purge
  110.  
  111. --add-module=/home/firs/nginx-1.4.6/modules/nginx-dav-ext-module --add-module=/home/firs/nginx-1.4.6/modules/nginx-
  112.  
  113. development-kit --add-module=/home/firs/nginx-1.4.6/modules/nginx-echo --add-module=/home/firs/nginx-1.4.6/modules/ngx-
  114.  
  115. fancyindex --add-module=/home/firs/nginx-1.4.6/modules/nginx-http-push --add-module=/home/firs/nginx-1.4.6/modules/nginx-lua
  116.  
  117. --add-module=/home/firs/nginx-1.4.6/modules/nginx-upload-progress --add-module=/home/firs/nginx-1.4.6/modules/nginx-upstream-
  118.  
  119. fair --add-module=/home/firs/nginx-1.4.6/modules/ngx_http_substitutions_filter_module --add-module=/home/firs/nginx-rtmp-
  120.  
  121. module-master
  122.  
  123.  
  124. В процессе конфигурирования возможно будут появляться ошибки.
  125. Ошибка:
  126. ./configure: error: the HTTP rewrite module requires the PCRE library.
  127. You can either disable the module by using --without-http_rewrite_module
  128. option, or install the PCRE library into the system, or build the PCRE library
  129. statically from the source with nginx by using --with-pcre=<path> option.
  130.  
  131. исправляется установкой libpcre++-dev:
  132. # sudo apt-get install libpcre++-dev
  133.  
  134. SSL modules
  135. sudo apt-get install libssl-dev
  136.  
  137. GeoIP module
  138. sudo apt-get install libgeoip-dev
  139.  
  140. HTTP XSLT module
  141. sudo apt-get install libxslt1-dev
  142.  
  143. HTTP image filter module requires the GD library
  144. sudo apt-get install libgd2-noxpm-dev
  145.  
  146. Ошибка ./configure: error: C compiler gcc is not found
  147. apt-get install libc6-dev
  148.  
  149. ngx_http_lua_module
  150. sudo apt-get install libluajit-5.1-dev
  151.  
  152. /Build/NginX/nginxmodules/nginx_http_auth_pam/1.2/ngx_http_auth_pam_module.c:13:31: fatal error: security/pam_appl.h: No such
  153.  
  154. file or directory
  155. sudo apt-get install libpam-dev
  156.  
  157. /usr/bin/ld: cannot find -lperl
  158. libperl-dev
  159.  
  160. После успешного окончания конфигурирования увидим на экране что-то вроде:
  161. nginx path prefix: "/etc/nginx"
  162. nginx binary file: "/etc/nginx/sbin/nginx"
  163. nginx configuration prefix: "/etc/nginx"
  164. nginx configuration file: "/etc/nginx/nginx.conf"
  165. nginx pid file: "/var/run/nginx.pid"
  166. nginx error log file: "/var/log/nginx/error.log"
  167. nginx http access log file: "/var/log/nginx/access.log"
  168. nginx http client request body temporary files: "/var/lib/nginx/body"
  169. nginx http proxy temporary files: "/var/lib/nginx/proxy"
  170. nginx http fastcgi temporary files: "/var/lib/nginx/fastcgi"
  171.  
  172. Теперь можно собрать бинарник nginx - выполняем 2 команды:
  173. # make
  174. # make install
  175.  
  176. Последним этапом является настройка для запуска новой версии nginx в автоматическом режиме. Вероятнее всего установленный nginx
  177.  
  178. из репозиториев лежит в папке /usr/share/nginx, новая версия установлена где-то в другом месте. Запускающий скрипт для nginx
  179.  
  180. стандартно хранится по адресу: /usr/sbin/nginx. Необходимо переименовать этот файл и установить симлинк на файл запуска в новой
  181.  
  182. версии:
  183. user@name: cd /usr/sbin
  184. user@name: mv nginx nginx_old
  185. user@name: ln -s /path/to/new/version/nginx-1.6.2/sbin/nginx nginx
  186. user@name: nginx -V
  187. user@name: nginx -t
  188. user@name: service nginx restart
  189.  
  190.  
  191. ------------------------------------------------------------------------------------
  192.  
  193. Авторизация стримера
  194. ?user=user&pass=pass
  195.  
  196. http://phpez.com/uncategorized/4.html
  197.  
  198.  
  199. nginx.conf
  200. http {
  201. limit_conn_zone $server_name zone=perserver:10m;
  202.  
  203. # nginx default configs...
  204.  
  205. server {
  206. listen 80;
  207. server_name localhost;
  208.  
  209. location /stat {
  210. rtmp_stat all;
  211. rtmp_stat_stylesheet stat.xsl;
  212. }
  213.  
  214. location /stat.xsl {
  215. root /usr/local/src/nginx-rtmp-module;
  216. }
  217.  
  218. location /control {
  219. rtmp_control all;
  220. }
  221.  
  222. error_page 500 502 503 504 /50x.html;
  223. location = /50.html {
  224. root html;
  225. }
  226.  
  227. location ~ \.php$ {
  228. root html;
  229. fastcgi_pass 127.0.0.1:9000;
  230. fastcgi_index index.php;
  231. fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
  232. include fastcgi_params;
  233. }
  234. location /hls {
  235. limit_conn perserver 10;
  236. root /tmp;
  237. }
  238. }
  239. }
  240.  
  241.  
  242.  
  243. rtmp {
  244. server {
  245. listen 1935;
  246. ping 30s;
  247. notify_method get;
  248. buflen 5s;
  249. drop_idle_publisher 30s;
  250. max_connections 55;
  251.  
  252. application myapp {
  253. live on;
  254.  
  255. # запись видео
  256. #record all;
  257. #record_path /mnt/rec;
  258. #record_suffix _%d-%b-%y_%H-%M-%S.flv;
  259.  
  260. hls on;
  261. hls_path /tmp/hls;
  262. hls_fragment 5s;
  263. on_publish http://localhost:80/on_publish.php;
  264. }
  265. }
  266.  
  267.  
  268. on_publish.php
  269. <?php
  270.  
  271. // ?user=user&pass=pass
  272.  
  273. $user = isset($_GET['user']) ? $_GET['user'] : '';
  274. $pass = isset($_GET['pass']) ? $_GET['pass'] : '';
  275.  
  276. if (empty($user) || empty($pass)) {
  277. echo "wrong query input";
  278. header('HTTP/1.0 404 Not Found');
  279. exit();
  280. }
  281.  
  282. $saveuser = user;
  283. $savepass = pass;
  284.  
  285. if (strcmp($user, $saveuser) == 0 && strcmp($pass, $savepass) == 0) {
  286. echo "Username and Password OK";
  287. } else {
  288. echo "Username or Password wrong";
  289. header('HTTP/1.0 404 Not Found');
  290. exit();
  291. }
  292.  
  293. ?>
  294.  
  295.  
  296. Использование:
  297. FMS URL:
  298. rtmp://localhost:1935/myapp
  299. mystream?user=rtmp&pass=12345
  300.  
  301. on_publish.php положить в каталог /usr/share/nginx/html
  302. ---------------------------------------------------------------------------------------------
  303.  
  304. Multi-worker statistics and control with nginx "per-worker-listener" patch
  305.  
  306. http://nginx-rtmp.blogspot.ru/2013/06/multi-worker-statistics-and-control.html
  307. https://github.com/arut/nginx-patches
  308.  
  309. ---------------------------------------------------------------------------------------------
  310. Модуль статистики для nginx
  311.  
  312. --with-http_stub_status_module
  313.  
  314. Конфиг:
  315. location /basic_status {
  316. stub_status;
  317. }
  318. ---------------------------------------------------------------------------------------------
  319. Блокируем обновления nginx
  320.  
  321. 1) Смотрим расширенный статус требуемого пакета:
  322. dpkg --get-selections | grep nginx
  323.  
  324. 2) Блокируем обновления пакета (ставим на него "Hold"):
  325. sudo apt-mark hold nginx nginx-common nginx-extras
  326.  
  327. 3) Смотрим результат:
  328. dpkg --get-selections | grep nginx
  329. -------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement