Ubuntu 17.04 編譯安裝 Nginx 1.9.9 配置 https 免費證書
阿新 • • 發佈:2022-04-28
Ubuntu 17.04 編譯安裝 Nginx 1.9.9 配置 https 免費證書
安裝 Nginx
安裝依賴
$ apt-get update
$ apt-get install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev
$ apt-get install openssl
$ apt-get install libssl-dev
下載並解壓
$ cd /opt/ $ wget http://nginx.org/download/nginx-1.9.9.tar.gz $ tar zxvf nginx-1.9.9.tar.gz
編譯
$ cd nginx-1.9.9
$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module
安裝
$ make
$ make && make install
預設安裝在/usr/local/nginx
裡面有四個目錄:
- conf: 配置資料夾,最重要檔案是nginx.conf
- html: 靜態網頁資料夾
- logs: 日誌資料夾
- sbin: nginx 的可執行檔案,啟動、停止等操作
常用命令
正確性檢查
每次修改nginx配置檔案後都要進行檢查
$ /usr/local/nginx/sbin/nginx -t
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
啟動
$ /usr/local/nginx/sbin/nginx
瀏覽器輸入本機IP ,看到如下內容證明安裝成功
Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.
停止
$ /usr/local/nginx/sbin/nginx -s stop
重啟
$ /usr/local/nginx/sbin/nginx -s reload
配置證書
安裝 acme.sh
安裝很簡單, 一個命令:
curl https://get.acme.sh | sh
生成證書
cd ~/.acme.sh/
apt install socat
sh acme.sh --issue -d docker.souyunku.com --standalone
複製證書
mkdir -p /certs
cd /root/.acme.sh/docker.souyunku.com
cp docker.souyunku.com.cer /certs
cp docker.souyunku.com.key /certs
配置Nginx
vim /usr/local/nginx/conf/nginx.conf
server {
listen 443;
ssl on;
ssl_certificate /certs/docker.souyunku.com.cer;
ssl_certificate_key /certs/docker.souyunku.com.key;
}
每次修改nginx配置檔案後都要進行檢查
$ /usr/local/nginx/sbin/nginx -t
啟動Nginx
$ /usr/local/nginx/sbin/nginx
測試證書
瀏覽器訪問:https://docker.souyunku.com/
Contact
- 作者:鵬磊
- 出處:http://www.ymq.io
- Email:[email protected]
- 版權歸作者所有,轉載請註明出處
- Wechat:關注公眾號,搜雲庫,專注於開發技術的研究與知識分享