缺省情况下openwrt带的Nginx是没带ngx_http_ssl_module的,需要重新编译一个ngxin版本带上ngx_http_ssl_module,
编译安装nginx
nginx -v #查看当前安装nginx版本nginx -V #查看当前安装nginx版本的详细信息#下载当前nginx版本的源码wget http://nginx.org/download/nginx-1.12.2.tar.gztar -xzvf nginx-1.12.2.tar.gz#编译nginx还需要安装下列包gcc-c++ zlib zlib-devel pcre pcre-devel openssl openssl-devel#安装编译器opkg install gccln -s /usr/bin/gcc-4.9 /usr/bin/cc #不然会提示C compiler cc is not found#下载libpcre的源码wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gzcd nginx的源码目录# –prefix 即编译后nginx的安装目录./configure --prefix=/usr --with-http_stub_status_module --with-http_ssl_module --with-pcre=/root/pcre-8.43 --with-openssl=/usr/bin --with-zlib=/usr/lib#上面代码会再当前目录下生成个Makefile文件 和objs文件夹,objs文件夹内还有个Makefile可直接修改make #开始编译make install #安装到上面指定的--prefix目录
SSL配置文件
全局配置:
# 运行用户,默认即是nginx,可以不进行设置user nginx;#Nginx进程,一般设置为和CPU核数一样worker_processes 1;#错误日志存放目录error_log /var/log/nginx/error.log warn;#进程pid存放位置pid /var/run/nginx.pid;events {worker_connections 1024; # 单个后台进程的最大并发数}http {include /etc/nginx/mime.types; #文件扩展名与类型映射表default_type application/octet-stream; #默认文件类型#设置日志模式log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log /var/log/nginx/access.log main; #nginx访问日志存放位置sendfile on; #开启高效传输模式#tcp_nopush on; #减少网络报文段的数量keepalive_timeout 65; #保持连接的时间,也叫超时时间#gzip on; #开启gzip压缩include /etc/nginx/conf.d/*.conf; #包含的子配置项位置和文件}
站点配置:
server {server_name yuming.cn; ##需要代理的域名listen 443 ssl;#定义服务器的默认网站根目录位置root /web/www/website/dist;#设定本虚拟主机的访问日志access_log logs/nginx.access.log main;#腾讯云推荐的配置ssl on; ##如果安装的是新版本下不需要ssl_certificate certPath/cert.pem; #证书ssl_certificate_key certPath/cert.key;#私钥ssl_session_timeout 3m;#超时时间ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#优先采取服务器算法ssl_prefer_server_ciphers on;location / {proxy_pass http://120.xx.xx.xx:9006; ##这里写需要转发的项目地址}#静态文件,nginx自己处理location ~ ^/(images|javascript|js|css|flash|media|static)/ {#过期30天,静态文件不怎么更新,过期可以设大一点,#如果频繁更新,则可以设置得小一点。expires 30d;}#禁止访问 .htxxx 文件# location ~ /.ht {# deny all;#}}server{listen 80;server_name XXX.com;#访问http的时候自动跳转到httpsrewrite ^(.*) https://$host$1 permanent;}
重新加载配置
nginx -t #检查nginx配置文件语法nginx -s reload #重启nginx并重新加载配置文件
参考链接:
https://aotu.io/notes/2016/08/16/nginx-https/index.html
https://juejin.im/post/5c0144036fb9a04a102f046a
