nginx配置HTTPS服务器
一、 ubuntu配置nginx v1.4.6 HTTPS服务器
1.首先确保机器上安装了openssl和openssl-devel
pip install openssl
pip install openssl-devel
- 1.
- 2.
2.创建服务器私钥,命令会让你输入一个口令:
openssl genrsa -des3 -out server.key 1024 // 生成私钥
- 1.
第一步生成server.key密码:123456
3.创建签名请求的证书(CSR):
> openssl req -new -key server.key -out server.csr
> 1 Country Name (2 letter code) [AU]:CN ←输入国家代码
> 2 State or Province Name (full name) [Some-State]:SHANGHAI← 输入省名
> 3 Locality Name (eg, city) []:SHANGHAI ←输入城市名
> 4 Organization Name (eg, company) [Internet Widgits Pty Ltd]:11 ← 输入公司名
> 5 Organizational Unit Name (eg, section) []:11 ← 输入组织单位名
> 6 Common Name (eg, YOUR name) []:111.11.11.1 ← 输入主机名
> 7 Email Address []:xxx@gmail.com ←输入电子邮箱地址
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
4.在加载SSL支持的Nginx并使用上述私钥:
openssl rsa -in server.key -out server_nopwd.key
- 1.
5.配置nginx最后标记证书使用上述私钥和CSR:
openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt
- 1.
6.修改Nginx配置文件,让其包含新标记的证书和私钥:
http {
include server/*.cn;
}
- 1.
- 2.
- 3.
7.修改Nginx配置文件,让其包含新标记的证书和私钥:
server {
listen 443;
server_name xx.online www.xx.online;
ssl on;
ssl_certificate /hk/keys/server.crt;
ssl_certificate_key /hk/keys/server_nopwd.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_prefer_server_ciphers on;
charset utf-8;
location /media {
alias /11/resource/project/media;
}
location /static {
alias /11/project/static;
}
location / {
uwsgi_pass 127.0.0.1:9011;
include /11/project/uwsgi_params;
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
8.启动nginx服务器.
如果出现“[emerg] 10464#0: unknown directive “ssl” in /usr/local/nginx-0.6.32/conf/nginx.conf:74”则说明没有将ssl模块编译进nginx,在configure的时候加上“–with-http_ssl_module”即可
[root@localhost nginx-1.4.4]# ./configure –prefix=/usr/local/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module
service nginx reload
service nginx restart
- 1.
- 2.
- 3.
9.测试网站是否能够通过https访问
https://xx.online/admin
10.同时支持80和443同时访问配置:
server {
listen 80 default backlog=2048;
listen 443 ssl;
}
- 1.
- 2.
- 3.
- 4.