手动部署LNMP环境debian

查看debian/ubuntu版本:

cat /etc/issue

更新系统:

apt-get update && apt-get upgrade -y

安装依赖:

apt -y install build-essential libpcre2-dev zlib1g-dev git dbus manpages-dev aptitude g++ wget curl unzip libssl-dev libxslt-dev libgd-dev libgeoip-dev vim

校准时间:

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && date -R

下载/安装/解压libmaxminddb

wget https://github.com/maxmind/libmaxminddb/releases/download/1.13.3/libmaxminddb-1.13.3.tar.gz && tar -zxvf libmaxminddb-1.13.3.tar.gz && cd libmaxminddb-1.13.3 && ./configure
make && make install && ldconfig && cd
git clone https://github.com/leev/ngx_http_geoip2_module.git

下载/安装/解压 openssl

wget -nc --no-check-certificate https://github.com/openssl/openssl/releases/download/openssl-4.0.1/openssl-4.0.1.tar.gz && tar -zxvf openssl-4.0.1.tar.gz

下载/解压 nginx

wget -nc --no-check-certificate https://nginx.org/download/nginx-1.30.2.tar.gz && tar -zxvf nginx-1.30.2.tar.gz

删除 nginx.tar.gz:

rm -rf nginx-1.30.2.tar.gz && rm -rf openssl-4.0.1.tar.gz && rm -rf libmaxminddb-1.13.3.tar.gz && cd nginx-1.30.2

添加编译插件:

./configure --prefix=/etc/nginx \
    --with-threads \
    --with-file-aio \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_v3_module \
    --with-http_realip_module \
    --with-http_sub_module \
    --with-http_gzip_static_module \
    --with-http_auth_request_module \
    --with-http_secure_link_module \
    --with-http_stub_status_module \
    --with-cc-opt='-march=native -O3' \
    --with-stream \
    --with-stream_ssl_module \
    --with-stream_realip_module \
    --add-dynamic-module=../ngx_http_geoip2_module \
    --with-stream_ssl_preread_module \
    --with-compat \
    --with-openssl-opt=enable-tls1_3 \
    --with-openssl=../openssl-4.0.1

编译/安装 nginx

make && make install

配置nginx服务:

cat >/etc/systemd/system/nginx.service <<EOF
[Unit]
Description=A high performance web server and a reverse proxy server
Documentation=man:nginx(8)
After=network.target nss-lookup.target

[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStartPre=/etc/nginx/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/etc/nginx/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/etc/nginx/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /etc/nginx/logs/nginx.pid
TimeoutStopSec=5
KillMode=mixed

[Install]
WantedBy=multi-user.target
EOF

添加配置文件:

mkdir -p /etc/nginx/ssl /etc/systemd/system/nginx.service.d && printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
cd && rm -rf nginx-1.30.2 openssl-4.0.1 libmaxminddb-1.13.3 ngx_http_geoip2_module
wget -P /etc/nginx/GeoLite2 https://raw.githubusercontent.com/P3TERX/GeoLite.mmdb/download/GeoLite2-Country.mmdb

安装MariaDB php:

apt install php-fpm php-mysql mariadb-server -y

安装php插件:

apt install php-curl php-gd php-imagick php-intl php-mbstring php-zip php-dom -y

mysql或MariaDB安全加固:
会设置密码,界面1直接回车,剩的都选Y:

mariadb-secure-installation

root登录:

mariadb -u root -p

查看当前的数据库:

show databases;

创建数据库非root用户名密码:

create database wordpress; create user name@localhost identified by 'password';

授予权限:

grant all privileges on wordpress.* to name@localhost; flush privileges;
  • 使密码生效
ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("password");

退出:

exit

下载https://typecho.org/ 解压放在/etc/nginx/html文件夹下,

安装wordpress

cd /etc/nginx/html && wget https://cn.wordpress.org/latest-zh_CN.zip && unzip latest-zh_CN.zip && mv wordpress/* /etc/nginx/html && rm -rf latest-zh_CN.zip wordpress && cd

用的非root账户要给html文件夹赋给权限:

chown -R www-data:www-data /etc/nginx/html

安装nginx配置文件

vim /etc/nginx/conf/nginx.conf

在第一行添加

load_module /etc/nginx/modules/ngx_http_geoip2_module.so;
load_module /etc/nginx/modules/ngx_stream_geoip2_module.so;
user  root;

http {块下添加

include conf.d/default.conf;
	# GeoIP2 国家识别
	map $http_x_forwarded_for $clientRealIp {
		"" $remote_addr;
		~^(?P<firstAddr>[0-9\.]+),?.*$ $firstAddr;
	}
	geoip2 /etc/nginx/GeoLite2/GeoLite2-Country.mmdb {
		auto_reload 5m;
		$geoip2_data_country_code default=XX source=$clientRealIp country iso_code;
	}
	map $geoip2_data_country_code $allowed_country {
		CN      yes;
		JP      yes;
		HK      yes;
		US      yes;
		CA      yes;
		FR      yes;
		default no;
	}

server {块下的

location / {添加

	if ($allowed_country = no) {
	    return 404;
	}

添加dhparam

curl https://ssl-config.mozilla.org/ffdhe2048.txt > /etc/nginx/ssl/dhparam

开启BBR:

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf && echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf && sysctl -p && lsmod | grep bbr

加载单元:

systemctl daemon-reload

开启nginx:

systemctl start nginx

开启状态:

systemctl status nginx

开机自动启动:

systemctl enable nginx

重新启动:

systemctl restart nginx

停止nginx:

service nginx stop

开启php8.2-fpm:

systemctl start php8.4-fpm

开启状态:

systemctl status php8.4-fpm

开机自动启动:

systemctl enable php8.4-fpm

重新启动:

systemctl restart php8.4-fpm

开启mysql:

systemctl start mariadb.service

开启状态:

systemctl status mariadb.service

开机自动启动:

systemctl enable mariadb.service

重新启动:

systemctl restart mariadb.service

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注