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
复制代码
测试证书
浏览器访问:docker.souyunku.com/
Contact
- 作者:鹏磊
- 出处:www.ymq.io
- Email:admin@souyunku.com
- 版权归作者所有,转载请注明出处
- Wechat:关注公众号,搜云库,专注于开发技术的研究与知识分享