Nginx unit 源码安装初体验
Nginx unit 源码安装初体验
上次介绍了从yum的安装方法(https://www.cnblogs.com/wang-li/p/9684040.html),这次将介绍源码安装,目前最新版为1.4,()Current latest version is 1.4, released on September 20, 2018.
我们就安装1.4,然后搭配PHP 7
PHP安装
略过,给编译参数即可
# /usr/local/php7/bin/php -i | grep config Configure Command => './configure' '--prefix=/usr/local/php7' '--enable-fpm' '--with-fpm-user=php' '--with-fpm-group=php' '--enable-embedded-mysqli' '--with-mysqli=mysqlnd' '--with-libxml-dir' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-zlib-dir' '--with-bz2' '--with-openssl' '--enable-soap' '--enable-mbstring' '--enable-sockets' '--enable-exif' '--with-ldap' '--with-gettext' '--enable-bcmath' '--with-pcre-regex' '--enable-embed' #
Nginx Unit介绍
Nginx Unit是一个动态Web和应用程序服务器,旨在以多种语言运行应用程序。单位是轻量级,多语言,并通过API动态配置。服务器的设计允许根据工程或操作的需要重新配置特定的应用参数。
支持的语言:
Python
PHP
Go
Perl
Ruby
JavaScript/Node.js 和 Java 即将推出
构建工具make gcc的安装
# yum install gcc make -y
下载nginx unit包,地址:https://unit.nginx.org/download/
# wget https://unit.nginx.org/download/unit-1.4.tar.gz
目前最新版的就是1.4(当前时间,2018-09-24 00:10:53)
下载之后,利用tar解压,可以用./configure --help 查看帮助
安装:
unit 安装 # ./configure --prefix=/usr/local/unit # make # make install unit-php安装 查看帮助 # ./configure php --help 如果操作系统存在多个php,可以使用--config参数指定php-config相应的版本即可 安装 # ./configure php 如果出现如下报错: # ./configure php configuring PHP module checking for PHP ... found + PHP SAPI: [cli embed fpm phpdbg cgi] checking for PHP embed SAPI ... not found ./configure: error: no PHP embed SAPI found. # 因为为系统没有发现php对应sapi,如果安装完php后,请将libphp.so拷贝至系统lib目录下,如我的机器: # cp -a /usr/local/php7/lib/libphp7.so /usr/lib64/但是必须要保证一点,PHP编译参数中必须包含--enable-embed才行,否则不会产生so文件 /usr/local/php7 是我php源码安装的地址 /usr/lib64/ 是系统放.so文件地方 然后执行make && make install
使用unit
注册unit
启动程序
监听的端口是127.0.0.1的8224端口
# ./sbin/unitd --control
获取8224的内容,可以看到,内容为空
# curl
{
"listeners": {},
"applications": {}
}
我们将会写我们的unit配置json文档,例如:http://unit.nginx.org/configuration/ 要运行程序,最低得配置必须至少包含一个侦听器和关联的应用程序
# cat /etc/unit/start.json
{
"listeners": {
"*:8300": {
"application": "blogs"
}
},
"applications": {
"blogs": {
"type": "php7",
,
"root": "/usr/local/nginx/php",
"index": "index.php",
"user": "php",
"group": "php",
"options": {
"file": "/usr/local/php7/lib/php.ini"
}
}
}
}
#
当然,root路径的值,在服务器是有内容的:
# cat /usr/local/nginx/php/index.php
<?php
phpinfo();
?>
#
当json编写完毕后,可以试着用如下网页工具进行对json的检测:http://www.bejson.com/
顺便提一下,如果需要使用curl的unix-socket的话,需要将curl软件升级不低于7.4的才可以,curl下载地址:https://curl.haxx.se/download/
下载
# wget https://curl.haxx.se/download/curl-7.55.0.tar.gz
安装
# ./configure # make # make install
查看版本
如果在编译的时候不指定安装目录,则会安装到/usr/local/bin下面
# /usr/local/bin/curl --version curl (x86_64-pc-linux-gnu) libcurl/ OpenSSL/ Release-Date: -- Protocols: dict file ftp ftps gopher http https imap imaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: IPv6 Largefile NTLM NTLM_WB SSL libz UnixSockets HTTPS-proxy #
将json put至我们的unit刚刚启动的方法中
# /usr/local/bin/curl -X PUT -d@/etc/unit/start.json '127.0.0.1:8224/config'
{
"success": "Reconfiguration done."
}
#
注意,我们不能将json文件put至127.0.0.1:8224上,应该put至127.0.0.1:8224/config上才行,否则的话,会报错Invalid method,我曾遇到过此问题,于是乎在github上询问了一下,大佬告诉我的方法(https://github.com/nginx/unit/issues/169)


接下来我们访问ip+端口的方法,试着能不能打开网页,可以看到,我们通过域名+8300的形式,可以打开网页

与nginx集成
没有安装nginx可以参考文档:https://www.cnblogs.com/wang-li/p/9030718.html
配置一下nginx conf
# sed -n '194,200p' nginx.conf
location / {
root php;
index index.php index.html index.htm;
proxy_pass http://127.0.0.1:8300;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#
检查语法,平滑重启nginx
# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful # /usr/local/nginx/sbin/nginx -s reload #
通过访问Nginx的方式,也可以获取相应的网页:

查看Nginx的log可以看到:

下次我将尝试着用unit代替之前的php-fpm,
Nginx unit 源码安装初体验的更多相关文章
- 关于nginx的源码安装方式
Nginx(engine x)是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器, 也是一个 IMAP/POP3/SMTP 代理服务器.在高连接并发的情况下, ...
- 编译nginx的源码安装subs_filter模块
使用nginx的反向代理功能搭建nuget镜像服务器时,需要针对官方nuget服务器的响应内容进行字符串替换,比如将www.nuget.org替换为镜像服务器的主机名,将https://替换为http ...
- nginx 的源码安装
安装nginx之前要做的准备工作有:安装如下库 (1)gzip模块需要 zlib 库 (2)rewrite模块需要 pcre 库 (3)ssl 功能需要openssl库 还有一种简单的方法就是 yum ...
- NFS, web,负载均衡,Nginx yum 源码安装
作业一:nginx服务1.二进制安装nginx 2.作为web服务修改配置文件 3.让配置生效,验证配置 [root@localhost ~]# systemctl stop firewalld.s ...
- linux应用之nginx的源码安装及配置(centos)
1.准备工作选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL.Nginx是C写的,需要用GCC编译:Nginx的 ...
- zabbix,php,nginx,mysql源码安装 神仙操作
→软件包 mkdir /soft/ cd /soft ♦下载以下软件包 nginx-1.14.2.tar.gz wget http://nginx.org/download/nginx-1.14.2. ...
- linux nginx+php源码安装
PHP安装 1)下载 wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 2)解压 tar –xf php-5.6.30 3)进入目录 cd ...
- Nginx源码安装及调优配置
导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优 ...
- nginx在Centos7.5下源码安装和配置
安装nginx 安装nginx依赖包 yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim 进入目录/root/se ...
随机推荐
- 第二章 FFmpeg常用命令
2.1 FFmpeg常见的命令大概分为6个部分 ffmpeg信息查询部分 公共操作参数部分 文件主要操作参数部分 视频操作参数部分 字幕操作参数部分 2.1.1 FFmpeg的封装转换 FFmpeg ...
- pyton unittest
在说unittest之前,先说几个概念: TestCase 也就是测试用例 TestSuite 多个测试用例集合在一起,就是TestSuite TestLoader是用来加载TestCase到Test ...
- oninput、onchange与onpropertychange事件的区别, 与input输入框实时检测
这几天项目着急,同时也学到好多以前没有接触过的知识.oninput.onchange与onpropertychange事件的区别, 与input输入框实时检测 onchange事件只在键盘或者鼠标操作 ...
- python中的第三方日志模块logging
基本上每个系统都有自己的日志系统,可以使自己写的,也可以是第三方的.下面来简单介绍一下python中第三方的日志模块,入手还是比较简单的,但是也很容易给自己埋雷. 下面是我参考的资料链接 入手demo ...
- ORACLE在IMP时候出现数据丢失
IMP-00019: 由于 ORACLE 错误 12899 而拒绝行 IMP-00003: 遇到 ORACLE 错误 12899 ORA-12899: 列 "JACKEYJ".&q ...
- 日志模块logging
import logging # 设置日志基础样式 logging.basicConfig(level=logging.INFO, format='levelname:%(levelname)s fi ...
- 【函数】raise 函数(小窗help)
在Python中,要想引发异常,最简单的形式就是输入关键字raise,后跟要引发的异常的名称. 异常名称标识出具体的类: Python异常处理是那些类的对象. 执行raise语句时,Python会创建 ...
- leetcode4
public class Solution { public double FindMedianSortedArrays(int[] nums1, int[] nums2) { var nums = ...
- 25.Hibernate-配置文件.md
目录 1.主配置文件 1.1定义 1.1.1分类 1.1.2分类 1.1.3不使用配置文件生成表 1.2教程 2. 映射配置文件 1.主配置文件 1.1定义 1.1.1分类 在hibernate的配置 ...
- Python代码的人机大战(循环嵌套)
第一次动手写随笔,记录一下今早的1.5小时努力成果 题目是这样的 : 人和机器进行猜拳游戏写成一个类,首先选择角色:1 曹操 2张飞 3 刘备,然后选择的角色进行猜拳:1剪刀 2石头 3布 玩家输入一 ...