为什么 wordpress 不能 运行 在我的 nginx 上?

why wordpress can't run on my nginx?

cat /etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
}

http {
server {
    listen 8080;
    server_name localhost;
    index index.html index.htm index.php;
    root /var/www/html;
}

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        gzip on;
        gzip_disable "msie6";
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

cat /etc/apache2/sites-enabled/000-default.conf

server {
    listen 8080;
    server_name localhost;

    root /var/www/html;
    index index.html;

    location / {
            try_files $uri $uri/ =404;
    }
}

何时在浏览器中输入 127.0.0.1:8080。

何时输入 127.0.0.1:8080/wp 我的 wordpress 是在浏览器中构建的。 自动下载了一个文件,文件内容如下:

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

为什么我的wordpress不能在nginx上正常显示?

让我们一一解决这些问题:

1 - 403 禁止响应

您收到此回复的原因很可能是由于您的 /var/www 目录权限不足。 像这样更改这些权限:

$ sudo chmod 0755 -R /var/www

2 - 提供包含 PHP 代码的文本文件(扩展名为 BIN)而不是 WP

这是因为您缺少合适的软件包 (php5-fpm) 或您的 conf 文件中存在一些错误配置。

首先,确保 /var/www/html 目录中的所有内容都属于用户 www-data,像这样:

$ sudo chown -R www-data /var/www/html/*

现在,如果您还没有安装 php5-fpm 软件包,请使用您发行版的软件包管理器。对于 Ubuntu:

$ sudo apt-get install php5-fpm

接下来,您必须对 3 个配置文件进行一些小的更改:

A)/etc/php5/fpm/pool.d/www.conf

确保以下行存在,如果不存在则添加

listen = /var/run/php5-fpm.sock

B)/etc/php5/fpm/php.ini 找到以下(可能默认注释)行

;cgi.fix_pathinfo=1

取消注释并将其值设置为 0

C)/etc/nginx/nginx.conf

进行以下更改:

在您的服务器规则添加以下规则块(就在root /var/www/html; 行):

location / {
        try_files $uri $uri/ /index.html;
    }

    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

最后,重启 php5-fpm 和 nginx 服务。 在 Ubuntu 中(没有 systemd):

$ sudo service php5-fpm restart
$ sudo service nginx restart

这应该有助于解决这些问题。

您可以在 nginxWordpress here.

上找到(有点高级的)文档