第六篇 Nginx使用

243 阅读1分钟

1.安装

  • 装修新房
yum install gcc-c++ # gcc环境
yum install -y pcre pcre-devel #pcre-devel 是使用 pcre 开发的一个二次开发库
yum install -y zlib zlib-devel #nginx 使用 zlib 对 http 包的内容进行 gzip
yum install -y openssl openssl-devel #需要在 Centos 安装 OpenSSL 库
  • 接新娘
wget -c https://nginx.org/download/nginx-1.19.6.tar.gz
  • 掀开你的盖头来
tar -zxvf nginx-1.19.6.tar.gz
  • 打扮一番 进入nginx-1.19.6目录
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module #添加ssl模块
make
  • 动次打次
/sbin/nginx -s start
/sbin/nginx -s stop
/sbin/nginx -s reload

配置https证书

http转https配置

    server {
        listen       80;
        server_name  www.52progress.com;
        rewrite ^(.*) https://$server_name$1 permanent;
    }

https配置

    server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      server.crt;
        ssl_certificate_key  server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   /usr/local/web/portalSite;
            index  index.html index.htm;
        }
    }

偶遇

  • gzip: stdin has more than one entry--rest ignored 需要安装gzip
yum install unzip
  • nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:99 在nginx运行./configure里,添加如下命令即可,然后重新安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module #添加ssl模块
make