nginx ssl证书配置

简介:

1、Nginx安装与配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   安装pcre
  #cd /usr/local/src
  #yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
  #wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
  # tar zxvf pcre-8.35.tar.gz
  #cd pcre-8.35
  # ./configure
  # make && make install
  
  安装nginx
  #wget http://nginx.org/download/nginx-1.13.0.tar.gz
  # tar zxvf nginx-1.13.0.tar.gz 
  #./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 
  --with-pcre= /usr/local/src/pcre-8 .35
  # make && make install
  
  创建 Nginx 运行使用的用户 www:
  # groupadd www 
  # useradd -g www www

配置nginx.conf ,将/usr/local/nginx/conf/nginx.conf替换为以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[root@bogon conf] #  cat /usr/local/nginx/conf/nginx.conf
 
user www www;
worker_processes 2;  #设置值和CPU核心数一致
error_log  /usr/local/webserver/nginx/logs/nginx_error .log crit;  #日志位置和日志级别
pid  /usr/local/webserver/nginx/nginx .pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
   use epoll;
   worker_connections 65535;
}
http
{
   include 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' ;
   
#charset gb2312;
      
   server_names_hash_bucket_size 128;
   client_header_buffer_size 32k;
   large_client_header_buffers 4 32k;
   client_max_body_size 8m;
      
   sendfile on;
   tcp_nopush on;
   keepalive_timeout 60;
   tcp_nodelay on;
   fastcgi_connect_timeout 300;
   fastcgi_send_timeout 300;
   fastcgi_read_timeout 300;
   fastcgi_buffer_size 64k;
   fastcgi_buffers 4 64k;
   fastcgi_busy_buffers_size 128k;
   fastcgi_temp_file_write_size 128k;
   gzip  on; 
   gzip_min_length 1k;
   gzip_buffers 4 16k;
   gzip_http_version 1.0;
   gzip_comp_level 2;
   gzip_types text /plain  application /x-javascript  text /css  application /xml ;
   gzip_vary on;
  
   #limit_zone crawler $binary_remote_addr 10m;
  #下面是server虚拟主机的配置
  server
   {
     listen 80; #监听端口
     server_name localhost; #域名
     index index.html index.htm index.php;
     root  /usr/local/nginx/html ; #站点目录
       location ~ .*\.(php|php5)?$
     {
       #fastcgi_pass unix:/tmp/php-cgi.sock;
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_index index.php;
       include fastcgi.conf;
     }
     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
     {
       expires 30d;
   # access_log off;
     }
     location ~ .*\.(js|css)?$
     {
       expires 15d;
    # access_log off;
     }
     access_log off;
   }
 
}

Nginx 其他命令

以下包含了 Nginx 常用的几个命令:

1
2
3
4
5
#/usr/local/nginx/sbin/nginx -t                   #测试nginx配置正确性
# /usr/local/nginx/sbin/nginx                     #启动Nginx
#/usr/local/nginx/sbin/nginx -s reload            # 重新载入配置文件
#/usr/local/nginx/sbin/nginx -s reopen            # 重启 Nginx
#/usr/local/nginx/sbin/nginx -s stop              # 停止 Nginx

2、Nginx SSl安装与配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#yum install openssl -y
#yum install openssl-devel -y
#cd /usr/local/nginx/ssl
#openssl genrsa -des3 -out server.key 1024
#openssl req -new -key server.key -out server.csr
#openssl rsa -in server.key -out server_nopwd.key
#openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt
 
完成上述后,我们在目录下会得到以下文件
 
# ls
server.crt  server.csr  server.key  server_nopwd.key
 
 
编辑nginx配置文件,加入以下语句
#vi nginx.conf
   
     server {
         listen       80;
         listen       443 ssl;         #开启ssl
         server_name  localhost;
         ssl_certificate    ssl /server .crt;     #证书配置
         ssl_certificate_key ssl /server_nopwd .key;    #证书配置
      ..... 
      .....
      }
重启nginx,这样就生效了

验证

wKiom1kk-7ej9vKvAAAfTNg_EuM577.png-wh_50



本文转自 jackjiaxiong 51CTO博客,原文链接:http://blog.51cto.com/xiangcun168/1928898

相关文章
|
1月前
|
存储 应用服务中间件 Linux
nginx配置证书和私钥进行SSL通信验证
nginx配置证书和私钥进行SSL通信验证
69 4
|
3月前
|
负载均衡 监控 应用服务中间件
配置Nginx反向代理时如何指定后端服务器的权重?
配置Nginx反向代理时如何指定后端服务器的权重?
240 61
|
3月前
|
安全 应用服务中间件 网络安全
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
253 60
|
3月前
|
安全 应用服务中间件 网络安全
配置Nginx反向代理实现SSL加密访问的步骤是什么?
我们可以成功地配置 Nginx 反向代理实现 SSL 加密访问,为用户提供更安全、可靠的网络服务。同时,在实际应用中,还需要根据具体情况进行进一步的优化和调整,以满足不同的需求。SSL 加密是网络安全的重要保障,合理配置和维护是确保系统安全稳定运行的关键。
329 60
|
2月前
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
866 8
|
2月前
|
存储 应用服务中间件 nginx
nginx反向代理bucket目录配置
该配置实现通过Nginx代理访问阿里云OSS存储桶中的图片资源。当用户访问代理域名下的图片URL(如 `http://代理域名/123.png`)时,Nginx会将请求转发到指定的OSS存储桶地址,并重写路径为 `/prod/files/2024/12/12/123.png`。
116 5
|
2月前
|
负载均衡 前端开发 应用服务中间件
负载均衡指南:Nginx与HAProxy的配置与优化
负载均衡指南:Nginx与HAProxy的配置与优化
193 3
|
1月前
|
数据建模 网络安全
阿里云SSL证书不同类型DV、OV和EV如何收费?单域名和通配符SSL价格整理
阿里云SSL证书提供免费和收费版本,涵盖DV、OV、EV多种类型。收费证书品牌包括DigiCert、GlobalSign等,价格从238元/年起。免费SSL证书由Digicert提供,单域名有效3个月,每个实名主体每年可领取20个。具体价格和详情见阿里云SSL官方页面。
|
3天前
|
云安全 运维 安全
阿里云免费版SSL证书申请及部署图文教程指导
SSL证书是个人和企业搭建网站不可或缺的云安全产品,SSL证书能够为网站和移动应用(APP)及小程序提供数据HTTPS加密协议访问,保障数据的安全。阿里云SSL证书有收费版的也有免费版的,有的新手用户由于是初次在阿里云申请SSL证书,可能不是很清楚免费版证书的申请和部署流程,本文为以图文形式为大家展示阿里云免费版SSL证书最新的申请及部署教程,以供参考。
|
1月前
|
数据建模 网络安全
阿里云SSL证书不同类型DV、OV和EV如何收费?单域名和通配符SSL价格整理
阿里云SSL证书提供免费和收费选项。收费证书包括:DV单域名WoSign 238元/年,DigiCert通配符DV 1500元/年,GlobalSign OV企业型1864元/年等。免费SSL证书由Digicert提供,有效期3个月,每年可领取20个单域名证书。更多详情及价格表请参考阿里云官方页面。