帮助中心

如果没有找到您需要的问题,随时联系我们

Nginx服务器配置入门教程

2025-12-22 云服务器帮助

Nginx是高性能的Web服务器和反向代理服务器。

安装Nginx:

CentOS:
yum install nginx -y

Ubuntu:
apt install nginx -y

启动服务:
systemctl start nginx
systemctl enable nginx

配置文件位置:

  • 主配置:/etc/nginx/nginx.conf
  • 站点配置:/etc/nginx/conf.d/

基本站点配置:

server {
  listen 80;
  server_name www.example.com example.com;
  root /var/www/html;
  index index.php index.html;

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

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

反向代理配置:

location /api/ {
  proxy_pass http://127.0.0.1:8080/;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
}

SSL配置:

server {
  listen 443 ssl;
  ssl_certificate /path/to/cert.pem;
  ssl_certificate_key /path/to/key.pem;
}

检查配置并重载:

nginx -t
nginx -s reload

返回列表

相关文章

定时任务Crontab使用教程
Docker容器入门教程
SSH密钥登录配置教程
服务器性能监控指南
Telegram