Install and configure SSL nginx mac implement the access Https

A, nginx installation

 

-e Ruby "$ (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
BREW install nginx install nginx nginx -v displays the version number
打开nginx文件夹
cd /usr/local/etc/nginx
启动nginx
sudo nginx or nginx
Enter localhost in the browser you can access, such as the following pages, that the installation was successful

Close nginx
sudo nginx -s stop or nginx -s stop 

 重启nginx

sudo nginx -s reload 或者 nginx -s reload 
Second, the configuration
1、找到Nginx文件夹
cd /usr/local/etc/nginx
2、openssl生成自签名证书

  Create the server private key command will let you enter a password

 openssl genrsa -out server.key (played by private name) 1024

      According to the private key to generate the certificate request, create a certificate signing request (CSR)

openssl req -new -key server.key (played by private name) -out server.csr (certificate name)

  The following options are at least a write before they can successfully generate a certificate

Country Name (2 letter code) []:ch
State or Province Name (full name) []:
Locality Name (eg, city) []:
Organization Name (eg, company) []:
Organizational Unit Name (eg, section) []:
Common Name (eg, fully qualified host name) []:
Email Address []:
 在加载SSL支持的Nginx并使用上述私钥时除去必须的口令:
$ cp server.key server.key.org
$ openssl rsa -in server.key.org -out server.key

  Finally, mark certificate using the private key and CSR

openssl x509 -req -in server.csr -out server.crt -signkey server.key -days 3650

 3, configure nginx: Modify /usr/local/etc/nginx/nginx.conf file

   Restart nginx 

 sudo nginx -s reload 或者 nginx -s reload 

  4、修改host文件

 

 vi /private/etc/hosts

 

 127.0.0.1 test.10dian.cm # configure domain

 

 

 Third, access

 

  Enter your configured to access the domain name

 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/pwei/p/https_nginx.html