龙空技术网

Nginx 自签https 证书(反向代理)

进技之路 1101

前言:

现在看官们对“nginx正向代理用户名密码”大概比较关心,咱们都想要知道一些“nginx正向代理用户名密码”的相关文章。那么小编同时在网摘上搜集了一些有关“nginx正向代理用户名密码””的相关资讯,希望大家能喜欢,朋友们快快来了解一下吧!

以下操作在centos 下执行:

cd/opt/ssl 证书制作路径

1)openssl genrsa -des3 -out domain.key 1024

生成RSA密钥(过程需要设置一个密码,记住这个密码)

2)openssl rsa -in domain.key -out domain_nopass.key

拷贝一个不需要输入密码的密钥文件

3)openssl req -new -key domain.key -out domain.csr

这里会提示输入国家,地区组织,email等信息.最重要的一个是"common name",需要与网站域名相同.

[root@localhost ssl]# openssl req -new -key domain.key -out domain.csr

Enter pass phrase for domain.key: ####1) 密码

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a CN.

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) []:zj 省

Locality Name (eg, city) [Default City]:hz 城市

Organization Name (eg, company) [Default Company Ltd]:tset 机构名称

Organizational Unit Name (eg, section) []:test 单位名称

Common Name (eg, your name or your server's hostname) []:domain.com 网站域名

Email Address []: 邮箱 可以回车

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []: 可以回车

An optional company name []: 可以回车

输入完这些就会生成一个domain.csr文件,提交给ssl提供商的时候就是这个csr文件.当然这里并没有向任何证书提供商申请,而是自己签发证书.

使用上面的密钥和CSR对证书签名

$ openssl x509 -req -days 365 -in domain.csr -signkey domain.key -out domain.crt

备注:这个365 时间可以多写点。

检测nginx是否支持SSL:

$ nginx -V

如果有显示-with-http_ssl_module表示已编译openssl,支持安装ssl.

如果没有,请重新编译安装nginx

参考配置文件

server {

listen 80;

listen [::]:80;

server_name x.x.x.x; #可以写成服务器地址

root /usr/share/nginx/html;

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;

location = /404.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

location /status {

stub_status on;

access_log off;

}

location / {

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass ; ###反向代理地址

rewrite ^(.*)$ permanent;

}

}

# Settings for a TLS enabled server.

server {

listen 443 ssl http2;

listen [::]:443 ssl http2;

server_name 10.100.124.6;

ssl_certificate "/opt/ssl/domain.pem"; ## 证书地址

ssl_certificate_key "/opt/ssl/domain_nopass.key"; ### 证书地址

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 10m;

ssl_ciphers HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers on;

# # Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

location / {

proxy_redirect off;

proxy_set_header Host $host;

proxy_set_header X-real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass ; ## 反向代理地址,如无反向代理地址可以家#注解

}

}

}

标签: #nginx正向代理用户名密码