1. 一键脚本

bash <(curl -Lso- https://files.kkktu.com/nginx/install.sh)

2. 脚本详情


echo -n "entry nginx version: (default:1.25.3)"

read nginx_version

sudo apt-get update -y

sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev -y


if [ -z $nginx_version]; then

curl -o /tmp/nginx-$nginx_version.tar.gz https://nginx.org/download/nginx-$nginx_version.tar.gz

echo "download completed"

tar zxvf /tmp/nginx-$nginx_version.tar.gz -C /tmp

cd /tmp/nginx-$nginx_version
./configure --prefix=/usr/local/lib/nginx --with-http_ssl_module


sudo make install

sudo rm /usr/bin/nginx
sudo ln -s /usr/local/lib/nginx/sbin/nginx /usr/bin/nginx

sudo rm -rf /tmp/nginx-$nginx_version

sudo rm -rf /tmp/nginx-$nginx_version.tar.gz
useradd www
sudo mkdir -p /home/www/nginx/conf.d

sudo chmod 777 /home/www/nginx/conf.d
curl -o /tmp/nginx.conf https://files.kkktu.com/nginx/nginx.conf
curl -o /tmp/example.conf https://files.kkktu.com/nginx/example.conf

sudo mv /tmp/nginx.conf /usr/local/lib/nginx/conf
mv /tmp/example.conf /home/www/nginx/conf.d

curl -o /tmp/nginx.service https://files.kkktu.com/nginx/nginx.service
sudo mv /tmp/nginx.service /lib/systemd/system/nginx.service

sudo mkdir -p /var/log/nginx

sudo systemctl enable nginx
sudo systemctl start nginx


user  www;
worker_processes  auto;

error_log  /var/log/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /run/nginx.pid;

events {
    worker_connections  1024;

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    include /home/www/nginx/conf.d/*.conf;


# Stop dance for nginx
# =======================
# ExecStop sends SIGSTOP (graceful stop) to the nginx process.
# If, after 5s (--retry QUIT/5) nginx is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if nginx is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
# nginx signals reference doc:
# http://nginx.org/en/docs/control.html
Description=A high performance web server and a reverse proxy server
After=network.target nss-lookup.target

ExecStartPre=/usr/bin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/bin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/bin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid


3. nginx服务指令

sudo systemctl enable nginx #开机启动nginx
sudo systemctl restart nginx #重启nginx
sudo systemctl reload nginx #重载nginx配置
sudo systemctl restart nginx #启动nginx
sudo systemctl status nginx #查看nginx服务状态

Revision #21
Created 21 November 2023 08:08:47 by Admin
Updated 22 November 2023 08:16:38 by Admin