How to configure an https server using nginx
First, make sure that openssl and openssl-devel are installed on the machine.
# Yum install openssl
# Yum install openssl-devel
Then, issue the certificate to yourself.
# Cd/usr/local/nginx/conf
# Openssl Gen RSA-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
Now that the certificate has been generated, the following is how to configure nginx
Server {
Listen 443;
Ssl on;
Ssl_certificate/usr/local/nginx/conf/server. crt;
Ssl_certificate_key/usr/local/nginx/conf/server_nopwd.key;
}
Restart nginx.
Ps: If "[emerg] 10464 #0: unknown directive" ssl "in/usr/local/nginx-0.6.32/conf/nginx appears. conf: 74 "indicates that the ssl module is not compiled into nginx, add" -- with-http_ssl_module "to configure ^
Now the https server has been built, but how can the browser trust the certificate issued by itself?
Today, I finally learned how to import the previously generated server. crt file to the certificate manager of the system:
Control panel-> Internet Options-> Content-> publisher-> trusted root certificate authority-> Import-Select server. crt
Supplement: simultaneous access of http and https in Nginx environment
After configuring the SSL certificate for nginx, https can be accessed normally. The http access error 400 is displayed. The nginx configuration is as follows:
Server {
Listen 80 default backlog = 2048;
Listen 443;
Server_name lvtao.net;
Root/var/www/html;
Ssl on;
Ssl_certificate/usr/local/Tengine/sslcrt/lvtao.net. crt;
Ssl_certificate_key/usr/local/Tengine/sslcrt/lvtao.net. key;
}
The following error is reported during http access:
400 Bad Request
The plain HTTP requset was sent to HTTPS port. Sorry for the inconvenience.
Please report this message and include the following information to us.
Thank you very much!
This problem occurs only when the http request is sent to the https port.
Server {
Listen 80 default backlog = 2048;
Listen 443 ssl;
Server_name lvtao.net;
Root/var/www/html;
Ssl_certificate/usr/local/Tengine/sslcrt/lvtao.net. crt;
Ssl_certificate_key/usr/local/Tengine/sslcrt/lvtao.net. Key;
}
Remove the ssl on; line, and write ssl at the end of port 443. In this way, both the http and https links can be used to solve the problem perfectly.