Home >Operation and Maintenance >Nginx >How to enable SSL configuration in Nginx server
Generate certificate
You can generate a simple certificate through the following steps:
First, enter the directory where you want to create the certificate and private key, for example:
$ cd /usr/local/nginx/conf
Create Server private key, the command will ask you to enter a password:
$ openssl genrsa -des3 -out server.key 1024
Create a certificate (csr) for the signing request:
$ openssl req -new -key server.key -out server.csr
Remove the necessary when loading nginx with SSL support and using the above private key Password:
$ cp server.key server.key.org $ openssl rsa -in server.key.org -out server.key
Enable an ssl virtual host
Write in the nginx.conf configuration file:
server { listen 443; server_name example.com; root /apps/www; index index.html index.htm; ssl on; ssl_certificate /etc/nginx/ssl/nginx.crt; ssl_certificate_key /etc/nginx/ssl/nginx.key; # ssl_protocols sslv3 tlsv1 tlsv1.1 tlsv1.2; # ssl_ciphers all:!adh:!export56:rc4+rsa:+high:+medium:+low:+sslv2:+exp; # ssl_prefer_server_ciphers on; }
where ssl_certificate represents the ca file and ssl_certificate_key represents Key file.
If you want to force http requests to https, you can do this:
server { listen 80; server_name example.me; return 301 https://$server_name$request_uri; }
The above is the detailed content of How to enable SSL configuration in Nginx server. For more information, please follow other related articles on the PHP Chinese website!