1. 前言
本来尝试了Docker的,但是由于一些原因,不太方便,还是选择原生 的nginx安装
2. 下载
下载:http://nginx.org/en/download.html
下载后,解压到一个目录,此目录随便,因为之后要编译
编译代码:
代码语言:javascript复制./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module
其实本文最主要的目的就是想记录上面的参数,方便万一以后需要使用
说明:
--prefix=
是安装的nginx目录--user
和group
需要提前创建www组和用户
acme.sh申请ssl,并且一些nginx配置ssl的参考,请见:
https://www.misiai.com/articles/30.html
3.systemctl
代码语言:javascript复制 vim /usr/lib/systemd/system/nginx.service
粘贴:
代码语言:javascript复制[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
代码语言:javascript复制systemctl daemon-reload
systemctl start nginx.service
汇总脚本
代码语言:javascript复制#!/bin/sh
groupadd www
useradd www -g www -s /sbin/nologin
sudo wget http://nginx.org/download/nginx-1.20.1.tar.gz
sudo tar zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module
make && make install
sudo tee /usr/lib/systemd/system/nginx.service <<-'EOF'
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl start nginx.service