首页 小编推荐 正文
  • 本文约1057字,阅读需5分钟
  • 104656
  • 63

wordpress nginx

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

WordPress 与 Nginx 配置

  1. 安装 Nginx 和 PHP
    • 安装 Nginx 和 PHP(通常是 PHP-FPM)。
    • 示例命令:
      
      sudo apt update
      sudo apt install...

WordPress 与 Nginx 配置

  1. 安装 Nginx 和 PHP

    • 安装 Nginx 和 PHP(通常是 PHP-FPM)。
    • 示例命令:
      sudo apt update
      sudo apt install nginx php-fpm php-mysql
  2. 配置 Nginx

    • 编辑默认的 Nginx 配置文件:
      sudo nano /etc/nginx/sites-available/default
    • 修改以下内容:

      server {
       listen 80;
       server_name yourdomain.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 和 PHP-FPM:
      sudo systemctl restart nginx
      sudo systemctl restart php7.4-fpm
  4. 安装 WordPress

    • 下载 WordPress:
      wget https://wordpress.org/latest.tar.gz
      tar -xzvf latest.tar.gz
      sudo mv wordpress/* /var/www/html/
    • 设置权限:
      sudo chown -R www-data:www-data /var/www/html
      sudo chmod -R 755 /var/www/html
  5. 配置 WordPress 数据库

    • 创建数据库和用户:
      CREATE DATABASE wordpress;
      GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost' IDENTIFIED BY 'password';
      FLUSH PRIVILEGES;
    • 访问 http://yourdomain.com 进行 WordPress 安装。
  6. 优化建议

    • 启用 HTTPS(使用 Certbot 获取免费 SSL 证书):
      sudo apt install certbot python3-certbot-nginx
      sudo certbot --nginx -d yourdomain.com

完成以上步骤后,WordPress 将在 Nginx 上正常运行。

48579 人点赞
评论