linux6系统下用nginx配置https

1、cd /usr/local/src 下载解压
wget http://nginx.org/download/nginx-1.14.0.tar.gz
./configure --prefix=/usr/local/nginx
make && make install
cd /usr/local/nginx/
vim conf/nginx.conf
linux6系统下用nginx配置https
linux6系统下用nginx配置https
cd /usr/local/src/nginx-1.14.0
./configure --with-http_stub_status_module --with-http_ssl_module --with-openssl=/usr/bin/openssl
make
cp -rfp objs/nginx /usr/local/nginx/sbin/nginx
sbin/nginx -t
sbin/nginx -s
如下配置

user nobody;

worker_processes 1;

events {

worker_connections  1024;

}

http {

include       mime.types;
default_type  application/octet-stream;
sendfile        on;
keepalive_timeout  65;

server {

    listen 80 default;
    server_name  jiaxin-test.eatjoys.cn;
    return       301     https://$host$request_uri;
    location / {
        root   html;
        index  index.html index.htm;
    }
    }

server {
    listen       443;
    server_name  jiaxin-https.eatjoys.cn;
    ssl on;
    root html;
    index  index.html index.htm;

proxy_pass http://127.0.0.1:8006$request_uri;

    ssl_certificate     /usr/local/nginx/cert/cert.pem;
    ssl_certificate_key  /usr/local/nginx/cert/cert.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 / {
        root   html;
        index  index.html index.htm;
    }
}

}

linux6系统下用nginx配置https

在centos中,配置nginx的https时,出现如下错误。

nginx: [emerg] unknown directive "ssl" in /usr/local/nginx/conf/nginx.conf:102

到解压的nginx目录下

./configure --with-http_ssl_module

当执行上面语句,出现./configure: error: SSL modules require the OpenSSL library.

用 yum -y install openssl openssl-devel

再执行./configure

重新执行./configure --with-http_ssl_module

make ,切记不能make install 会覆盖。

把原来nginx备份

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

把新的nginx覆盖旧的

cp objs/nginx /usr/local/nginx/sbin/nginx

出现错误时cp: cannot create regular file ‘/usr/local/nginx/sbin/nginx’: Text file busy

用cp -rfp objs/nginx /usr/local/nginx/sbin/nginx解决

测试nginx是否正确

/usr/local/nginx/sbin/nginx -t

(nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful)

重启nginx
/usr/local/nginx/sbin/nginx -s reload

上一篇:nagios短信报警(飞信fetion20080522004-linrh4)


下一篇:【数据蒋堂】第7期:硬盘的性能特征