初光是一种态度

← 返回教程列表

Nginx基础配置教程

分类:服务器管理 难度:中级

Nginx服务器配置

安装Nginx:

sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx

基础配置:

server {
    listen 80;
    server_name example.com;
    
    location / {
        root /var/www/html;
        index index.html index.htm;
    }
    
    location /api {
        proxy_pass http://localhost:3000;
    }
}

常用命令:

  • nginx -t:测试配置文件
  • nginx -s reload:重新加载配置
  • nginx -s stop:停止服务