nginx 配置 ssl

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

1.1 Nginx如果未开启SSL模块配置Https时提示错误

原因也很简单nginx缺少http_ssl_module模块编译安装的时候带上--with-http_ssl_module配置就行了但是现在的情况是我的nginx已经安装过了怎么添加模块其实也很简单往下看 做个说明我的nginx的安装目录是/usr/local/nginx这个目录我的源码包在/usr/local/src/nginx-1.6.2目录

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:37

1.2 Nginx开启SSL模块

查看nginx原有的模块

/usr/local/mysoft/nginx-1.18.0/sbin/nginx -V

在configure arguments:后面显示的原有的configure参数如下

--prefix=/usr/local/mysoft/nginx-1.18.0 --with-http_stub_status_module

那么我们的新配置信息就应该这样写

./configure --prefix=/usr/local/mysoft/nginx-1.18.0 --with-http_stub_status_module --with-http_ssl_module

运行上面的命令即可等配置完

配置完成后运行命令

make

这里不要进行make install否则就是覆盖安装

然后启动nginx仍可以通过命令查看是否已经加入成功

/usr/local/mysoft/nginx-1.18.0/sbin/nginx -V 

然后找到nginx安装目录并配置nginx.conf文件配置如下

user  root;
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;


    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #api负载均衡配置
    upstream apiServer {
		server 127.0.0.1:8081;
        server 127.0.0.1:8082;
    }
	#api服务1配置
    server {
		listen 443 ssl;
         server_name abc.com; #域名
         ssl_certificate cert/8588597_abc.com.pem;  #证书地址目录 这里在把cert文件夹放在conf下
         ssl_certificate_key cert/8588597_abc.com.key;#证书 这里在把cert文件夹放在conf下
         ssl_session_timeout 5m;
         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
         #表示使用的加密套件的类型。
         ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #表示使用的TLS协议的类型您需要自行评估是否配置TLSv1.1协议。
    	 ssl_prefer_server_ciphers on;

        location / {
           proxy_pass http://apiServer;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

	#前端服务配置
    server {
        listen       80;  #端口
        server_name  www.abc123.com; #域名
		#www.abc123.com/admin 跳转下面服务
		location /admin {
            alias   /home/java/admin-ui; #前端2代码的目录
            index  index.html index.htm;
        }
		
		#www.abc123.com 跳转下面服务
		location / {
            alias /home/java/guang-wang/; #前端1代码的目录
            index  index.html index.htm;
        }
    }

}

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: nginx