
在折腾香橙派的时候,由于是纯净版本的debian server 版本,安装nginx不出意外的话应该是无法找到这个模块的。
sudo apt install nginx
so,我们替换一下镜像源
这里我使用了阿里云 Debian 镜像源,根据您的 Debian 版本,您可以使用以下源地址:
Debian 10 (Buster)
deb https://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ buster main non-free contrib
deb https://mirrors.aliyun.com/debian-security buster/updates main
deb-src https://mirrors.aliyun.com/debian-security buster/updates main
deb https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
Debian 11 (Bullseye)
deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb https://mirrors.aliyun.com/debian-security bullseye-security/updates main
deb-src https://mirrors.aliyun.com/debian-security bullseye-security/updates main
deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
- 配置镜像源,编辑 sources.list 文件
使用文本编辑器打开 /etc/apt/sources.list
文件:
sudo nano /etc/apt/sources.list
- 替换现有源
将文件中的内容替换为上述相应版本的镜像源地址。
- 保存并退出
在 nano 中,使用 CTRL + O
保存文件,然后 CTRL + X
退出。
4. 更新软件包列表
完成源配置后,更新软件包列表:
sudo apt update
然后再尝试安装nginx,应该能成功啦。
5. 启动nginx
sudo systemctl start nginx
6. 设置开机启动
sudo systemctl enable nginx
7. 查看nginx状态
sudo systemctl status nginx
8.访问
默认80端口,localhost即可触达。
9.重启
sudo systemctl restart nginx
10. 停止
sudo systemctl top nginx
11.配置一个代理
1)Nginx 配置文件通常位于 /etc/nginx/sites-available/
目录。您可以创建一个新的配置文件,或者编辑默认配置文件。
创建一个新的配置文件,例如 my_proxy.conf
:
sudo nano /etc/nginx/sites-available/my_proxy.conf
文件内容如下:
server {
listen 80; # 监听 80 端口
server_name localhost; # 替换为您的域名或 IP
location / {
proxy_pass http://localhost:5000; # 将请求代理到后端服务
proxy_set_header Host $host; # 设置 Host 头
proxy_set_header X-Real-IP $remote_addr; # 真实客户端 IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 转发的 IP 地址
proxy_set_header X-Forwarded-Proto $scheme; # 转发的协议
}
}
server_name
: 用于指定域名或服务器的 IP 地址。
proxy_pass
: 指定请求代理的后端服务地址。
proxy_set_header
: 设置请求头,以便后端可以获取客户端信息。
2)启用配置
为了使新配置生效,您需要创建一个符号链接到 sites-enabled
目录:
sudo ln -s /etc/nginx/sites-available/my_proxy.conf /etc/nginx/sites-enabled/
当然你也直接建立在sites-enabled下面 无需使用连接
3)测试是否错误
sudo nginx -t
4)重新加载 Nginx
如果配置没有错误,重新加载 Nginx 以应用更改:
sudo sytemctl reload nginx
ok这就是debian新建nginx服务器的基本操作。