nginx libreSSL on Ubuntu 16.04 18.04 源码编译安装
TAGS: 技术文档 nginx nginx编译安装 libreSSL
create by jyo on 2018-07-15 contact code3346#gmail.com
TODO 暂未支持IPV6
以下操作于ubuntu x64 18.04 root身份下操作 同在 16.04予以一并生效
编译器工具
apt-get install build-essential libtool
系统类库依赖,可直接自动安装的,也可以手动编译安装 注意这里没有装openssl,因最近openssl漏洞愈演愈烈,下面将用libreSSL替换openSSL
apt-get install libpcre3 libpcre3-dev zlib1g-dev
下载文件准备 截止到2018-07-27 发稿日期,当前最新版本2.7.4
wget -O /usr/local/src/jemalloc-4.5.0.tar.bz2 http://xyzsetup.dlhis.com/isl-jemalloc-4.5.0.tar.bz2
wget -O /usr/local/src/libressl-2.7.4.tar.gz http://xyzsetup.dlhis.com/isl-libressl-2.7.4.tar.gz
wget -O /usr/local/src/nginx-1.14.0.tar.gz http://xyzsetup.dlhis.com/isl-nginx-1.14.0.tar.gz
编译安装 libreSSL
cd /usr/local/src
tar -zxf libressl-2.7.4.tar.gz && cd libressl-2.7.4
./configure --prefix=/usr/local --libdir=/usr/local/lib
make && make install
make clean
jemalloc 类库编译安装
tar -xjf jemalloc-4.5.0.tar.bz2
cd jemalloc-4.5.0
./configure --prefix=/usr/local/jemalloc --libdir=/usr/local/lib
make && make install
make clean
cd ../
## 两个类库依赖安装都完成后
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
ldconfig -v | fgrep jemalloc ## 查看jemalloc生效与否
ldconfig -v | fgrep libssl ## 查看libssl生效与否
nginx 编译安装脚本,将此脚本 另存为install,并授权
cd /usr/local/src && tar -zxf nginx-1.14.0.tar.gz
cd nginx
touch install-nginx && chmod +x ./install-nginx
./configure --with-openssl=/usr/local/src/libressl-2.7.4/ \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/conf/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-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module \
--with-stream \
--with-ld-opt="-ljemalloc"
mkdir -p /var/cache/nginx/client_temp
mkdir -p /var/cache/nginx/proxy_temp
mkdir -p /var/cache/nginx/fastcgi_temp
mkdir -p /var/cache/nginx/uwsgi_temp
mkdir -p /var/cache/nginx/scgi_temp
useradd -s /sbin/nologin -M nginx #这里先检查系统是否具备此用户信息
make && make install
创建 systemctl nginx.service服务
cd /etc/systemd/ && touch nginx.service
systemctl
# Stop dance for nginx
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /var/run/nginx.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
systemctl 操作
systemctl start nginx
systemctl status nginx
systemctl stop nginx
systemctl reload nginx
systemctl enable nginx
启动后 systemctl status nginx 查看一下日志是否会有异常
最后依然附上nginx conf文件 配置变量 中文说明参考
$arg_PARAMETER 这个变量包含在查询字符串时GET请求PARAMETER的值。
$args 这个变量等于请求行中的参数。
$binary_remote_addr 二进制码形式的客户端地址。
$body_bytes_sent 传送页面的字节数
$content_length 请求头中的Content-length字段。
$content_type 请求头中的Content-Type字段。
$cookie_COOKIE cookie COOKIE的值。
$document_root 当前请求在root指令中指定的值。
$document_uri 与$uri相同。
$host 请求中的主机头字段,如果请求中的主机头不可用,则为服务器处理请求的服务器名称。
$is_args 如果$args设置,值为"?",否则为""。
$limit_rate 这个变量可以限制连接速率。
$nginx_version 当前运行的nginx版本号。
$query_string 与$args相同。
$remote_addr 客户端的IP地址。
$remote_port 客户端的端口。
$remote_user 已经经过Auth Basic Module验证的用户名。
$request_filename 当前连接请求的文件路径,由root或alias指令与URI请求生成。
$request_body 这个变量(0.7.58+)包含请求的主要信息。在使用proxy_pass或fastcgi_pass指令的location中比较有意义。
$request_body_file 客户端请求主体信息的临时文件名。
$request_completion 未知。
$request_method 这个变量是客户端请求的动作,通常为GET或POST。
包括0.8.20及之前的版本中,这个变量总为main request中的动作,如果当前请求是一个子请求,并不使用这个当前请求的动作。
$request_uri 这个变量等于包含一些客户端请求参数的原始URI,它无法修改,请查看$uri更改或重写URI。
$scheme 所用的协议,比如http或者是https,比如rewrite ^(.+)$ $scheme://example.com$1 redirect;
$server_addr 服务器地址,在完成一次系统调用后可以确定这个值,如果要绕开系统调用,则必须在listen中指定地址并且使用bind参数。
$server_name 服务器名称。
$server_port 请求到达服务器的端口号。
$server_protocol 请求使用的协议,通常是HTTP/1.0或HTTP/1.1。
$uri 请求中的当前URI(不带请求参数,参数位于$args),可以不同于浏览器传递的$request_uri的值,它可以通过内部重定向,或者使用index指令进行修改。
如有错误,欢迎指出更正 mail-me code3346#gmail.com
God bless us