nginx 安装教程记录 debian12

Ydecl/忧

nginx 安装教程记录 debian12

过程记录

nginx install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev git build-essential -y #基础

mkdir /home/ydecl/tmp # 下载编译目录后续可删除
cd /home/ydecl/tmp

wget https://nginx.org/download/nginx-1.28.0.tar.gz

tar -zxvf nginx-1.28.0.tar.gz
cd nginx-1.28.0
### /home/user/nginx 安装目录,根据自己需求改!
./configure --prefix=/home/user/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-threads \
--with-file-aio

make -j$(nproc)
make install

host

1
sudo nano /etc/hosts #127.0.0.1 site1.com www.site1.com

html-conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 80;
server_name site1.com www.site1.com;

# 站点根目录
root /home/user/nginx/html/site1.com;
index index.html index.htm;

# 访问日志
access_log /home/user/nginx/logs/site1.com/access.log;
error_log /home/user/nginx/logs/site1.com/error.log;

location / {
try_files $uri $uri/ =404;
}

# 禁止访问隐藏文件
location ~ /\. {
deny all;
}
}

php-conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
server {
listen 80;
server_name site2.com www.site2.com;

# 站点根目录
root /home/user/nginx/html/site2.com;
index index.php index.html index.htm;

# 访问日志
access_log /home/user/nginx/logs/site2.com/access.log;
error_log /home/user/nginx/logs/site2.com/error.log;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

# PHP 处理配置
location ~ \.php$ {
# 根据您的 PHP-FPM 配置调整这里
# 如果是 Unix socket 方式
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; #先运行php

# 如果是 TCP 方式
# fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# 禁止访问隐藏文件
location ~ /\. {
deny all;
}
}

conf/nginx.conf

1
2
3
4
5
http {

... ...
include sites/enabled/*.conf;
}

使用

1
2
3
4
#检测配置文件
nginx -t
#重启
nginx -s reload
  • 标题: nginx 安装教程记录 debian12
  • 作者: Ydecl/忧
  • 创建于 : 2025-09-19 19:36:34
  • 更新于 : 2025-09-17 19:55:26
  • 链接: https://blog.yc2019.cn/posts/nginx-25.html
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。