Nginx配置443端口
操作分为两步一、密钥证书证书与密钥生成(利用jdk的toolkey工具)1.生成密钥(.keystore格式)keytool -genkey -alias cert -keypass password -keyalg RSA -keysize 1024 -validity 365 -keystore E:/keystore/cert.keystore -storepass password2.导出
·
操作分为两步
一、密钥证书
证书与密钥生成(利用jdk的toolkey工具)
1.生成密钥(.keystore格式)
keytool -genkey -alias cert -keypass password -keyalg RSA -keysize 1024 -validity 365 -keystore E:/keystore/cert.keystore -storepass password
2.导出证书(.cer格式)
keytool -export -alias cert -keystore E:/keystore/cert.keystore -storepass password -rfc -file E:/keystore/cert.cer
3.利用java的main函数生成密钥(注意生成密钥与证书的密码不要输错)
try {
BASE64Encoder encoder = new BASE64Encoder();
//读取文件内容
FileInputStream fis = new FileInputStream("E:/JXD/keystore/cert.keystore");
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(fis, "password".toCharArray());
PrivateKey key = (PrivateKey) ks.getKey("cert", "password".toCharArray());
String encoded = encoder.encode(key.getEncoded());
System.out.println(encoded);
is.close();
} catch (Exception e){
}
4.密钥记得添加前缀与后缀(cert.key)
-----BEGIN RSA PRIVATE KEY-----
此处为生成的密钥内容
-----END RSA PRIVATE KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAJcMosRArChkufiJdAvxv6HeHZ6B
/nviG2ihH72yuhCNil8eej7vNiYWdgyhqdsdfsdhVcm1+98GBAkBjeMg3rKs8TIlD
/s7Y3MtLE0SRkFiFG6cqizEcq7MYlEklDo+941McabuxaUPVXmjWurDV9t7/1qM8Ch87AlErAkEA
hRyvu2lU9VjPrCoBzlupSYdljaNUDKjRhtHXQ+Uy2gaWhoWgs1r8lgfxegcrNOq5pgd1eTEZd+Iw
UF/5pVcarw==
-----END RSA PRIVATE KEY-----
二、配置443端口
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl_certificate cert.cer;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
add_header Cache-Control no-store
root html;
index index.html index.htm;
#避免刷新页面后需要重新登录
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
location /prod-api/ {
proxy_pass http://localhost:8082/;
}
}
完整配置
#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;
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;
client_max_body_size 100m;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
add_header Cache-Control no-store;
root html;
index index.html index.htm;
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ^~ /prod-api/ {
proxy_pass http://127.0.0.1:8082/;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 443 ssl;
server_name localhost;
ssl_certificate cert.cer;
ssl_certificate_key cert.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
add_header Cache-Control no-store
root html;
index index.html index.htm;
#避免刷新页面后需要重新登录
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.+)$ /index.html last;
}
location /prod-api/ {
proxy_pass http://localhost:8082/;
}
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)