Linux下安装nginx 并且配置https域名

前提条件:centos 7.1,掌握Liunx基本指令

Nginx包下载地址:

http://nginx.org/download/nginx-1.8.0.tar.gz

Nginx依赖包下载地址:

1.gzip模块需要zlib库(在http://www.zlib.net/下载http://zlib.net/zlib-1.2.8.tar.gz)

2.rewrite模块需要pcre库(在http://www.pcre.org/下载ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/)

3.ssl功能需要openssl库(在http://www.openssl.org/下载http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz)

 
 2.2Nginx安装
   安装前确认linux下这些库已经安装

yum install perl 
yum install gcc
yum install gcc-c++
yum -y install net-tools

   将安装包放到/home/zwr/nginx_install目录下,
  然后再该目录下运行此脚本 注意自己下的版本的问题,如果和我的不一致就照着换名字,名字换好了下面这一大段脚本就直接贴上去运行就OK
#1.安装openssl-fips-2.0.9.tar.gz  
cd /home/zwr/nginx_install  
#解压安装文件  
tar -zxvf openssl-fips-2.0.9.tar.gz  
cd openssl-fips-2.0.9  
#prefix配置安装路径  
./config --prefix=/opt/openssl-fips-2.0.9  
make  
make install  
#2.安装zlib-1.2.8.tar.gz  
cd /home/zwr/nginx_install  
#解压安装文件  
tar -zxvf zlib-1.2.8.tar.gz  
cd zlib-1.2.8  
#prefix配置安装路径  
./configure --prefix=/opt/zlib-1.2.8  
make  
make install  
#3.安装pcre-8.37.tar.gz  
cd /home/zwr/nginx_install  
#解压安装文件  
tar -zxvf pcre-8.37.tar.gz  
cd pcre-8.37  
#prefix配置安装路径  
./configure --prefix=/opt/pcre-8.37  
make  
make install  
#4.安装nginx-1.8.0.tar.gz  
cd /home/zwr/nginx_install  
#解压安装文件  
tar -zxvf nginx-1.8.0.tar.gz  
cd nginx-1.8.0  
#with-pcre指定依赖包位置,prefix配置安装路径  
./configure --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-fips-2.0.9 --prefix=/opt/nginx-1.8.0  
make  
make install  
#5.至此Nginx的安装完成!  
#检测是否安装成功  
cd  /opt/nginx-1.8.0/sbin  
./nginx -t  
#6.启动nginx  
cd  /opt/nginx-1.8.0/sbin  
./nginx  
#7.查看端口  
netstat -ntlp

贴到这里为止

期间你可能会出现各种bug,比如端口占用,权限不够,ssl配置不生效啊,自己网上翻,都有都有
nginx.conf配置
http {
    include mime.types;
    default_type application/octet-stream;
    include /usr/local/nginx/conf/reverse-proxy.conf;
    sendfile on;
    keepalive_timeout 65;
    gzip on;
    client_max_body_size 50m; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户
    client_body_buffer_size 256k;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间(代理连接超时)
    proxy_read_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时)
    proxy_send_timeout 300s;
    proxy_buffer_size 64k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
    proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
    proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
    proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘
    proxy_ignore_client_abort on; #不允许代理端主动关闭连接
    server {
        listen 80;
        server_name localhost;
        location / {
            root html;
            index index.html index.htm;
        }
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
    }
}
配置上文incloud的 usr/local/nginx/conf/reverse-proxy.conf 文件
server {
    listen 443;
    server_name test.niubisb.cn; # 你的域名
    ssl on;
   
    index index.html index.htm;# 上面配置的文件夹里面的index.html
    ssl_certificate  cert/1991970_test.niubisb.cn.pem;# 改成你的证书的名字,证书自己去下
    ssl_certificate_key cert/1991970_test.niubisb.cn.key;# 你的证书的名字
    ssl_session_timeout 5m;
    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   https://ip地址:8080;  #所需要代理的地址
    }

  运行,代理https域名成功

猜你喜欢

转载自blog.csdn.net/SCDN_CP/article/details/88969843
今日推荐