[关闭]
@code33 2018-07-15T15:04:59.000000Z 字数 4831 阅读 793

nginx libreSSL on Ubuntu 16.04 18.04 NGINX配置(二)

技术文档 nginx nginx编译安装 libreSSL

create by jyo on 2018-07-15
contact code3346#gmail.com

TODO 暂未支持IPV6


以下操作于ubuntu x64 18.04 root身份下操作 同在 16.04予以一并生效

编译器工具

  1. apt-get install build-essential libtool

系统类库依赖,可直接自动安装的,也可以手动编译安装 注意这里没有装openssl,因最近openssl漏洞愈演愈烈,下面将用libreSSL替换openSSL

  1. apt-get install libpcre3 libpcre3-dev zlib1g-dev

下载文件准备

  1. wget -O /usr/local/src/jemalloc-4.5.0.tar.bz2 http://xyzsetup.dlhis.com/isl-jemalloc-4.5.0.tar.bz2
  2. wget -O /usr/local/src/libressl-2.7.4.tar.gz http://xyzsetup.dlhis.com/isl-libressl-2.7.4.tar.gz
  3. wget -O /usr/local/src/nginx-1.14.0.tar.gz http://xyzsetup.dlhis.com/isl-nginx-1.14.0.tar.gz

编译安装 libreSSL

  1. cd /usr/local/src
  2. tar -zxf libressl-2.7.4.tar.gz && cd libressl-2.7.4
  3. ./configure --prefix=/usr/local --libdir=/usr/local/lib
  4. make && make install
  5. make clean

jemalloc 类库编译安装

  1. tar -xjf jemalloc-4.5.0.tar.bz2
  2. cd jemalloc-4.5.0
  3. ./configure --prefix=/usr/local/jemalloc --libdir=/usr/local/lib
  4. make && make install
  5. make clean
  6. cd ../
  7. ## 两个类库依赖安装都完成后
  8. echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
  9. ldconfig
  10. ldconfig -v | fgrep jemalloc ## 查看jemalloc生效与否
  11. ldconfig -v | fgrep libssl ## 查看libssl生效与否

nginx 编译安装脚本,将此脚本 另存为install,并授权

  1. cd /usr/local/src && tar -zxf nginx-1.14.0.tar.gz
  2. cd nginx
  3. touch install-nginx && chmod +x ./install-nginx
  1. ./configure --with-openssl=/usr/local/src/libressl-2.7.4/ \
  2. --prefix=/usr/local/nginx \
  3. --sbin-path=/usr/sbin/nginx \
  4. --conf-path=/etc/nginx/conf/nginx.conf \
  5. --error-log-path=/var/log/nginx/error.log \
  6. --http-log-path=/var/log/nginx/access.log \
  7. --pid-path=/var/run/nginx.pid \
  8. --lock-path=/var/run/nginx.lock \
  9. --http-client-body-temp-path=/var/cache/nginx/client_temp \
  10. --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  11. --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  12. --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  13. --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  14. --user=nginx \
  15. --group=nginx \
  16. --with-http_ssl_module \
  17. --with-http_realip_module \
  18. --with-http_addition_module \
  19. --with-http_sub_module \
  20. --with-http_dav_module \
  21. --with-http_flv_module \
  22. --with-http_mp4_module \
  23. --with-http_gunzip_module \
  24. --with-http_gzip_static_module \
  25. --with-http_random_index_module \
  26. --with-http_secure_link_module \
  27. --with-http_stub_status_module \
  28. --with-http_auth_request_module \
  29. --with-http_slice_module \
  30. --with-mail \
  31. --with-mail_ssl_module \
  32. --with-file-aio \
  33. --with-http_v2_module \
  34. --with-stream \
  35. --with-ld-opt="-ljemalloc"
  36. mkdir -p /var/cache/nginx/client_temp
  37. mkdir -p /var/cache/nginx/proxy_temp
  38. mkdir -p /var/cache/nginx/fastcgi_temp
  39. mkdir -p /var/cache/nginx/uwsgi_temp
  40. mkdir -p /var/cache/nginx/scgi_temp
  41. useradd -s /sbin/nologin -M nginx #这里先检查系统是否具备此用户信息
  42. make && make install

创建 systemctl nginx.service服务

  1. cd /etc/systemd/ && touch nginx.service

systemctl

  1. # Stop dance for nginx
  2. # =======================
  3. #
  4. # ExecStop sends SIGSTOP (graceful stop) to the nginx process.
  5. # If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
  6. # and sends SIGTERM (fast shutdown) to the main process.
  7. # After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
  8. # SIGKILL to all the remaining processes in the process group (KillMode=mixed).
  9. #
  10. # nginx signals reference doc:
  11. # http://nginx.org/en/docs/control.html
  12. #
  13. [Unit]
  14. Description=A high performance web server and a reverse proxy server
  15. After=network.target
  16. [Service]
  17. Type=forking
  18. PIDFile=/var/run/nginx.pid
  19. ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
  20. ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
  21. ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
  22. ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /var/run/nginx.pid
  23. TimeoutStopSec=5
  24. KillMode=mixed
  25. [Install]
  26. WantedBy=multi-user.target

systemctl 操作

  1. systemctl start nginx
  2. systemctl status nginx
  3. systemctl stop nginx
  4. systemctl reload nginx
  5. systemctl enable nginx

启动后 systemctl status nginx 查看一下日志是否会有异常

最后依然附上nginx conf文件 配置变量 中文说明参考

  1. $arg_PARAMETER 这个变量包含在查询字符串时GET请求PARAMETER的值。
  2. $args 这个变量等于请求行中的参数。
  3. $binary_remote_addr 二进制码形式的客户端地址。
  4. $body_bytes_sent 传送页面的字节数
  5. $content_length 请求头中的Content-length字段。
  6. $content_type 请求头中的Content-Type字段。
  7. $cookie_COOKIE cookie COOKIE的值。
  8. $document_root 当前请求在root指令中指定的值。
  9. $document_uri $uri相同。
  10. $host 请求中的主机头字段,如果请求中的主机头不可用,则为服务器处理请求的服务器名称。
  11. $is_args 如果$args设置,值为"?",否则为""
  12. $limit_rate 这个变量可以限制连接速率。
  13. $nginx_version 当前运行的nginx版本号。
  14. $query_string $args相同。
  15. $remote_addr 客户端的IP地址。
  16. $remote_port 客户端的端口。
  17. $remote_user 已经经过Auth Basic Module验证的用户名。
  18. $request_filename 当前连接请求的文件路径,由rootalias指令与URI请求生成。
  19. $request_body 这个变量(0.7.58+)包含请求的主要信息。在使用proxy_passfastcgi_pass指令的location中比较有意义。
  20. $request_body_file 客户端请求主体信息的临时文件名。
  21. $request_completion 未知。
  22. $request_method 这个变量是客户端请求的动作,通常为GETPOST
  23. 包括0.8.20及之前的版本中,这个变量总为main request中的动作,如果当前请求是一个子请求,并不使用这个当前请求的动作。
  24. $request_uri 这个变量等于包含一些客户端请求参数的原始URI,它无法修改,请查看$uri更改或重写URI
  25. $scheme 所用的协议,比如http或者是https,比如rewrite ^(.+)$ $scheme://example.com$1 redirect;
  26. $server_addr 服务器地址,在完成一次系统调用后可以确定这个值,如果要绕开系统调用,则必须在listen中指定地址并且使用bind参数。
  27. $server_name 服务器名称。
  28. $server_port 请求到达服务器的端口号。
  29. $server_protocol 请求使用的协议,通常是HTTP/1.0HTTP/1.1
  30. $uri 请求中的当前URI(不带请求参数,参数位于$args),可以不同于浏览器传递的$request_uri的值,它可以通过内部重定向,或者使用index指令进行修改。

如有错误,欢迎指出更正 mail-me
code3346#gmail.com


God bless us

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注