?
#添加http模块
./configure --prefix=/usr/local/nginx --with-http_ssl_module
#编译
make
#安装
make install
#添加http模块
./configure --prefix=/usr/local/nginx --with-http_ssl_module
#编译
make
#备份原有的nginx
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#复制新编译好的nginx覆盖原有的nginx(需要先停掉原有的nginx服务)
cp ./objs/nginx /usr/local/nginx/sbin/
#启动nginx在/usr/local/nginx/sbin/路径下
./nginx
#启动之后可通过-V参数查看模块是否添加成功
/usr/local/nginx/sbin/nginx -V
该目录可以存放在任何位置,只要保证在nginx指定的配置文件中正确引入证书即可正常使用。
#实际使用中看服务器性能,如果足够好也可以使用4096位秘钥
openssl genrsa -des3 -out nginx.key 1024
Generating RSA private key, 1024 bit long modulus
.......++++++
...++++++
e is 65537 (0x10001)Enter pass phrase for nginx.key: ? ? ? ?#输入密码,自定义,不少于4个字符
Verifying - Enter pass phrase for nginx.key: ? ? #确认密码
openssl req -new -key nginx.key -out nginx.csr
Enter pass phrase for nginx.key: ? ? ? ? ? ? ? ? ? ? ? ? ? ? #输入刚刚创建的密码
You are about to be asked to enter information that will be incorporatedinto your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN ? ? ? ? ? ? ? ? ? ? ?#国家名称
State or Province Name (full name) []:ShangHai ? ? ? ? ? ?#省
Locality Name (eg, city) [Default City]:ShangHai ? ? ? ? ?#市
Organization Name (eg, company) [Default Company Ltd]:ACBC ? ? #公司
Organizational Unit Name (eg, section) []:Tech ? ? #部门
Common Name (eg, your name or your server's hostname) []:*.mydomain.com ? ? ?
#注意,此处应当填写你要部署的域名,如果是单个则直接添加即可,如果不确定,使用*,表示可以对所有mydomain.com的子域名做认证
Email Address []:admin@mydomain.com ? ?#以域名结尾即可
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []: ? ? ? ?#是否设置密码,可以不写直接回车
An optional company name []: ? ?#其他公司名称 可不写
openssl rsa -in nginx.key -out nginx_nopass.key
?Enter pass phrase for nginx.key: ? ? ? ?#之前RSA秘钥创建时的密码
writing RSA key
openssl x509 -req -days 3650 -in nginx.csr -signkey nginx.key -out nginx.crt
Signature ok
subject=/C=CN/ST=ShangHai/L=ShangHai/O=ACBC/OU=Tech/CN=*.mydomain.com/emailAddress=admin@mydomain.com
Getting Private key
Enter pass phrase for nginx.key: ? ? ? ? ?#RSA创建时的密码
实际生产中需要指定nginx的反向代理,可以通过引入指定的配置文件而不适用默认的nginx配置。
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
include /usr/local/nginx/conf.d/new.conf;
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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#切换到nginx的可执行文件目录下
./nginx -t
配置文件正确会返回successful,如果有错会提示在配置文件哪一行出错,需要回到配置文件进行修改。
#如果nginx在启动中,需要先停止服务,然后再进行重启
ps -ef | grep nginx
#查看nginx服务PID
kill nginx的进程号
#在nginx的可执行文件目录下重启nginx
./nginx
可正常访问说明配置成功