首页 小编推荐 正文
  • 本文约730字,阅读需4分钟
  • 104358
  • 57

nginx wordpress

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

Nginx + WordPress 配置

  1. 安装 Nginx 和 PHP
    • 安装 Nginx: sudo apt update && sudo apt install nginx
    • 安装 PHP 和相关模块: `sudo apt install php-...

Nginx + WordPress 配置

  1. 安装 Nginx 和 PHP

    • 安装 Nginx: sudo apt update && sudo apt install nginx
    • 安装 PHP 和相关模块: sudo apt install php-fpm php-mysql php-cgi
  2. 配置 Nginx
    编辑默认站点配置文件 /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. 设置 WordPress 文件权限

    • 解压 WordPress 到 /var/www/html。
    • 设置目录权限: sudo chown -R www-data:www-data /var/www/html
    • 设置文件权限: sudo find /var/www/html -type d -exec chmod 755 {} \;
    • 设置文件权限: sudo find /var/www/html -type f -exec chmod 644 {} \;
  4. 配置 WordPress 数据库
    创建 MySQL 数据库和用户,导入 WordPress SQL 文件。

  5. 完成安装
    在浏览器中访问 http://your-domain.com,按照提示完成 WordPress 安装。

48312 人点赞
评论