【问题标题】:How can I configure nginx to serve a Django app and a Wordpress site?如何配置 nginx 来为 Django 应用程序和 Wordpress 站点提供服务?
【发布时间】:2014-05-08 15:23:06
【问题描述】:

我对任何与系统管理员/nginx 相关的东西都比较陌生,并且正在尝试使用 Digital Ocean 的 VPS。

我有一个 Django 应用程序,我使用 Gunicorn 和 Supervisor 在我的域(根目录)上运行它(以重新启动进程)。我还为 Django 应用程序提供了一些静态文件。我现在想看看我是否也可以在同一台服务器上提供 Wordpress PHP 网站。

下面是我的 nginx 配置。它适用于 Django 应用程序及其静态文件,但 Wordpress 很奇怪:Wordpress 管理员工作正常,但前端失败(只是呈现一个空白页面)。有没有明显的错误?

不管怎样,这些是我想使用的 URL:

  • example.com/ – Django 应用程序
  • example.com/assets/* – 静态文件(用于 Django 应用)
  • example.com/blog – Wordpress 应用程序

这是 nginx 配置:

server {
    listen 80;
    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    server_name my.ip.goes.here;

    location /assets/ {
        alias /opt/foo/assets/;
        expires max;
        access_log off;
        add_header Pragma public;
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        proxy_ignore_headers "Cache-Control" "Expires" "X-Accel-Expires" "Set-Cookie";
    }

    location /blog/ {
        try_files $uri $uri/ /blog/index.php?q=$uri&$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location / {
        proxy_pass my.ip.goes.here:8001;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
    }
}

为了使 /blog/ 子文件夹正确地为 Wordpress 实例服务,我缺少什么?管理员 (/blog/wp-admin/index.php) 服务正常且完全可用。

【问题讨论】:

  • 看看nginx错误日志,有没有错误?
  • 我的配置中也找不到 404。您在哪里指明了您的 wordpress 文件的位置?

标签: php django wordpress nginx


【解决方案1】:

我自己的错误。配置是正确的(这是一个赠品,管理员工作正常,nginx 错误日志中没有任何内容):我已将现有的 Wordpress 数据库连接到新的 WP 安装,并且我使用的主题不存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-22
    • 2022-08-14
    • 2020-09-27
    • 1970-01-01
    • 2021-10-03
    • 2012-09-01
    • 2019-07-29
    • 1970-01-01
    相关资源
    最近更新 更多