简体   繁体   中英

How can I configure nginx to serve a Django app and a Wordpress site?

I'm relatively new to anything sysadmin/nginx-related, and experimenting with Digital Ocean's VPS.

I have a Django app which I've got running on my domain (on the root) using Gunicorn and Supervisor (to restart the process). I also serve some static files for the Django app. I'd now like to see if I can serve a Wordpress PHP site as well, all on the same server.

Below is my nginx configuration. It works for the Django app and its static files, but Wordpress is weird: the Wordpress admin works fine, but the frontend fails (just renders a blank page). Is there an obvious error?

For what it's worth, these are the URLs I'd like to be using:

  • example.com/ – Django app
  • example.com/assets/* – static files (for Django app)
  • example.com/blog – Wordpress app

Here's the nginx config:

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"';
    }
}

What am I missing to make the /blog/ subfolder properly serve the Wordpress instance? The admin ( /blog/wp-admin/index.php ) serves correctly and is fully usable.

My own error. The config was right (it was a giveaway that the admin worked fine and there was nothing in the nginx error log): I'd connected an existing Wordpress database to a fresh WP install and the theme I was using didn't exist.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM