1、nginx安裝
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install nginx // 安裝nginx
nginx -v // 顯示版本號
打開nginx文件夾
cd /usr/local/etc/nginx
啓動nginx
sudo nginx 或者 nginx
在瀏覽器中輸入 localhost 訪問便可,如出現如下頁面,即安裝成功
關閉nginx
sudo nginx -s stop 或者 nginx -s stop
重啓nginx
sudo nginx -s reload 或者 nginx -s reload
2、配置
一、找到Nginx文件夾
cd /usr/local/etc/nginx
二、openssl生成自簽名證書
建立服務器私鑰,命令會讓你輸入一個口令
openssl genrsa -out server.key(起的私鑰名字) 1024
根據私鑰生成證書申請,建立簽名請求的證書(CSR)
openssl req -new -key server.key(起的私鑰名字)-out server.csr(證書名字)
下面的選項至少寫一個,才能夠生成證書成功
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
最後標記證書使用上述私鑰和CSR
openssl x509 -req -in server.csr -out server.crt -signkey server.key -days 3650
三、配置nginx:修改/usr/local/etc/nginx/nginx.conf 文件
重起nginx
sudo nginx -s reload 或者 nginx -s reload
四、修改host文件
vi /private/etc/hosts
127.0.0.1 test.10dian.cm #須要配置的域名
3、訪問
輸入你配置好的域名便可訪問了