default Nginx is not SSL need to be added when compiling and installing the module. SSL Module!
the first is the need to install Nginx Service, here we do not do a detailed introduction, specific installation can refer to my " Nginx Introduction and Installation Configuration ".
Use Openssl Generate certificate
1 , Generate RSA method of the secret key
[email protected] conf]# OpenSSL genrsa-des3-out ke ll . Key 1024x768
Generatingrsa private key, 1024x768 bit long modulus
.++++++
.. ++++++
EIS 65537 (0x10001)
Enter Pass phrase for Kell . Key:
Verifying-enter Pass phrase for Kell . Key:
2 , generate a certificate request
[email protected] conf]# OpenSSL Req-new-key Kell . Key-out Kell . CSR
you will be asked to enter some information such as provinces, countries, etc., Email to enter the domain name suffix, the password is the one entered in the previous step
3 , copy a key file that does not need to enter a password
[email protected] conf]# OpenSSL rsa-in Kell . Key-out Kell _nopass.key
Enter Pass phrase for Kell . Key:
Writingrsa Key
Password Enter the password you entered last time
4 , self-issued certificates
[[email protected] conf] #opensslx509-req-days 365-in Kell . Csr-signkey Kell . Key-out Kell . CRT
Configuration Nginx configuration file
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
server {
#listen 80;
Listen 443;
SSL on;
ssl_certificate/application/nginx/conf/ Kell . crt;
ssl_certificate_key/application/nginx/conf/ Kell _nopass.key;
server_name www.etiantian.org;
Location/{
Root html/www;
Rewrite ^/(. *) https://$host/$1 permanent;
Index index.html index.htm;
#rewrite ^/(. *) https://$host/$1 permanent;
}
}
through the browser HTTPS can be accessed, if needed rewrite , you need to configure rewrite
through htpasswd Set Nginx Authenticated access
because htpasswd is a http service with the command, so we can install http service to get this command, or you can install only httpd -tools to install this command so that you don't have to install the entire http Service
installation htpasswd Command Tools
[Email protected]conf]# yum Install Httpd-tools
[Email protected]conf]# which htpasswd
/usr/bin/htpasswd
Create an account & Password
[[Email protected]conf]# htpasswd-bc/application/nginx/conf/htpasswd Wangzhan 123456
Addingpassword for user Wangzhan
[Email protected]conf]# chmod 400/application/nginx/conf/htpasswd
[Email protected]conf]# chown nginx/application/nginx/conf/htpasswd
[[Email protected]conf]# cat/application/nginx/conf/htpasswd
Wangzhan:b2sfluv5673ce
Add the following two lines to the configuration file
Auth_basic "wangzhan123456";
AUTH_BASIC_USER_FILE/APPLICATION/NGINX/CONF/HTPASSWD;
Restart the service, use the site access, will find the Input Authentication Password dialog box appears
This article is from the "System World" blog, please be sure to keep this source http://sgk2011.blog.51cto.com/1551358/1791148
SSL authentication and HTPASSWD authentication for Nginx service