Установка
curl -OL https://nginx.org/download/nginx-1.28.0.tar.gz
tar -xvzf nginx-1.28.0.tar.gz && rm nginx-1.28.0.tar.gz
curl -OL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.46/pcre2-10.46.tar.gz
tar -xvzf pcre2-10.46.tar.gz && rm pcre2-10.46.tar.gz
curl -OL https://github.com/openssl/openssl/releases/download/openssl-3.5.2/openssl-3.5.2.tar.gz
tar -xvzf openssl-3.5.2.tar.gz && rm openssl-3.5.2.tar.gz
apt-get install gcc zlib1g zlib1g-dev make
cd nginx-1.28.0/
./configure --prefix=/usr/local/nginx --with-pcre=../pcre2-10.46/ --with-openssl=../openssl-3.5.2/ --with-http_ssl_module
make && sudo make install
Alias
Ubuntu
echo 'alias nginx="sudo /usr/local/nginx/sbin/nginx"' >> ~/.bashrc
source ~/.bashrc
macOS
echo 'alias nginx="sudo /usr/local/nginx/sbin/nginx"' >> ~/.zshrc
source ~/.zshrc
Управление
macOS
# запуск
sudo launchctl bootstrap system /Library/LaunchDaemons/nginx.plist
# остановка
sudo launchctl bootout system/nginx
# reload
nginx -s reload
Ubuntu
sudo nano /etc/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable nginx
sudo systemctl start nginx
service nginx status|start|stop|restart
Проверка
sudo lsof -i:80
curl localhost
Certbot
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot certbot-nginx
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
certbot certonly --nginx --nginx-ctl /usr/local/nginx/sbin/nginx --nginx-server-root /usr/local/nginx/conf
auth_basic
sudo sh -c "echo -n 'sammy:' >> /usr/local/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /usr/local/nginx/.htpasswd"
auth_basic "You shall not pass!";
auth_basic_user_file /usr/local/nginx/.htpasswd;;
gistcomment-5370199