首页 小编推荐 正文
  • 本文约969字,阅读需5分钟
  • 103932
  • 56

wordpress nginx配置

温馨提示:本文最后更新于2025年5月31日 00:30,若内容或图片失效,请在下方留言或联系博主。
摘要

WordPress Nginx 配置

  1. 安装 Nginx 和 PHP
    • 确保服务器上已安装 Nginx 和 PHP-FPM。
    • 示例命令:
      
      sudo apt update
      sudo apt install nginx...

WordPress Nginx 配置

  1. 安装 Nginx 和 PHP

    • 确保服务器上已安装 Nginx 和 PHP-FPM。
    • 示例命令:
      sudo apt update
      sudo apt install nginx php-fpm php-mysql
  2. 配置 Nginx

    • 编辑默认站点配置文件:
      sudo nano /etc/nginx/sites-available/default
    • 替换内容为以下配置:

      server {
       listen 80;
       server_name your-domain.com;
      
       root /var/www/html;
       index index.php index.html index.htm;
      
       location / {
           try_files $uri $uri/ /index.php?$args;
       }
      
       location ~ \.php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # 根据PHP版本调整
       }
      
       location ~ /\.ht {
           deny all;
       }
      }
  3. 测试和重启 Nginx

    • 测试配置是否正确:
      sudo nginx -t
    • 如果无误,重启 Nginx:
      sudo systemctl restart nginx
  4. WordPress 相关配置

    • 确保 WordPress 的 wp-config.php 文件中数据库信息正确。
    • 设置权限:
      sudo chown -R www-data:www-data /var/www/html
      sudo chmod -R 755 /var/www/html
  5. HTTPS 配置(可选)

    • 安装 Certbot 并获取 SSL 证书:
      sudo apt install certbot python3-certbot-nginx
      sudo certbot --nginx -d your-domain.com
    • 按提示完成 HTTPS 配置。
  6. 优化(可选)

    • 启用 Gzip 压缩:
      gzip on;
      gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss;
    • 添加缓存头:
      add_header Cache-Control "public, max-age=3600";

完成以上步骤后,WordPress 应该可以通过 Nginx 正常运行。

48352 人点赞
评论