为已经安装nginx添加php模块,给已安装的NGINX添加新的模块

本文介绍了如何手动编译Nginx以包含特定版本的源码,并添加额外的模块,如rtmp。首先,查看当前Nginx的配置信息,然后下载相同版本的源码并解压。接着,在源码目录下执行`configure`,添加所需模块,如rtmp模块。完成配置后执行`make`进行编译,但不执行`make install`。将编译后的二进制文件替换原有Nginx,最后重启Nginx验证新模块是否生效。
摘要由CSDN通过智能技术生成

使用nginx -V,查看当前nginx的信息,包括版本号和configure编译配置信息

版本号 1.14.1

configure--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=\\\'-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC\\\' --with-ld-opt=\\\'-Wl,-z,relro -Wl,-z,now -pie\\\'

下载相同版本号的源码http://nginx.org/en/download.html

解压,cd到源码目录

下载解压要编译的模块源码和nginx源码目录同一目录

在nginx源码目录下执行configure

configure参数包括已安装的参数和你要添加的模块

例如./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt=\\\'-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC\\\' --with-ld-opt=\\\'-Wl,-z,relro -Wl,-z,now -pie\\\' --add-module=../nginx-rtmp-module-1.2.1

--add-module=../nginx-rtmp-module-1.2.1 就是我要添加的模块

configure完成后执行make编译

记住不要install

编译后的nginx在当前目录的objs文件夹内。

备份 /usr/sbin 目录下的nginx文件

把编译后的objs文件夹内的nginx问价移动到、usr/sbin 文件夹内

重启nginx

nginx -s stop

nginx

运行nginx -V发现已经包含需要的模块了

ngx_php功能是为nginx模块嵌入php脚本语言。别名为php-nginx-module。 特性 * 支持加载php.ini配置文件 * 支持原生php的全局变量$_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_SESSION... * 支持运行php代码与文件 * 支持RFC 1867文件上传协议 * 支持php错误输出 * 支持加载与运行PECL扩展 * 支持nginx的API在php中调用 环境 - PHP 5.3.*     PHP 5.4.*     PHP 5.5.*     PHP 5.6.* - nginx-1.4.7     nginx-1.6.3     nginx-1.8.1     nginx-1.9.15 安装 git clone https://github.com/rryqszq4/ngx_php.git wget 'http://nginx.org/download/nginx-1.6.3.tar.gz' tar -zxvf nginx-1.6.3.tar.gz cd nginx-1.6.3 export PHP_BIN=/path/to/php/bin export PHP_INC=/path/to/php/include/php export PHP_LIB=/path/to/php/lib ./configure --user=www --group=www \             --prefix=/path/to/nginx \             --with-ld-opt="-Wl,-rpath,$PHP_LIB" \             --add-module=/path/to/ngx_php/dev/ngx_devel_kit \             --add-module=/path/to/ngx_php 概要 user www www; worker_processes  4; events {     worker_connections  1024; } http {     include       mime.types;     default_type  application/octet-stream;     keepalive_timeout  65;          client_max_body_size 10m;        client_body_buffer_size 4096k;     php_ini_path /usr/local/php/etc/php.ini;     server {         listen       80;         server_name  localhost;              location /php {             content_by_php '                 echo "hello ngx_php";             ';         }     } } 标签:ngxphp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值