下载 Nginx 源码包

wget https://nginx.org/download/nginx-1.13.8.tar.gz
tar -zxvf nginx-1.13.8.tar.gz

nginx 下载地址

下载 pcre zlib openssl 源码包

wget http://zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz

tar -zxvf zlib-1.2.11.tar.gz
tar -zxvf pcre-8.41.tar.gz
tar -zxvf openssl-1.0.2n.tar.gz

zlib 下载地址(版本: 1.1.3 — 1.2.11)

pcre 下载地址(版本: 4.4 — 8.41)

openssl 下载地址

编译安装 nginx

cd nginx-1.13.8

./configure --prefix=/usr/local/nginx --user=loveyou --with-http_ssl_module --with-pcre=../pcre-8.41 --with-zlib=../zlib-1.2.11 --with-openssl=../openssl-1.0.2n

编译参数:

  • --prefix=/usr/local/nginx: 指定编译目录为/usr/local/nginx
  • --user=loveyou: 指定用户
  • --with-http_ssl_module: 开启 https 模块
  • --with-pcre: 指定 pcre 源码包路径
  • --with-zlib: 指定 zlib 源码包路径
  • --with-openssl: 指定 openssl 源码包路径
make
make install

常用命令

  1. nginx 启动 nginx 服务
  2. nginx -s stop停止
  3. nginx -s reload重新加载配资文件
  4. nginx -s reopen重启日志文件
  5. nginx -t测试配置文件

HTTPS 配置

server {
    listen 443;
    server_name www.domain.com;
    ssl on;
    ssl_certificate 1_www.domain.com_bundle.crt; #改为你自己的证书文件路径
    ssl_certificate_key 2_www.domain.com.key; #改为你自己的密钥文件路径
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    location / {
        root   html;
        index  index.html index.htm;
    }
}
server {
    listen 80;
    server_name www.domain.com;
    rewrite ^(.*) https://$host$1 permanent;
}

80 端口转发到 443 端口

反向代理

location /tt/ {
    proxy_pass http://www.pass.com:8000;
}

www.demo.com/tt 转发到 www.pass.com:8080

gzip 压缩

gzip            on;
gzip_min_length 1000;
gzip_comp_level 2;
gzip_proxied    expired no-cache no-store private auth;
gzip_types      *

常见错误

1.

报错: ./configure: error: C compiler cc is not found
执行: yum install gcc

2.

报错: configure: error: You need a C++ compiler for C++ support.
执行: yum install gcc gcc-c++ autoconf automake

参考文档

本文固定链接: http://www.js-code.com/cpp/cpp_59217.html