How to run Django and Wordpress using Nginx and Gunicorn at the same domain?

这一生的挚爱 提交于 2019-12-02 03:59:07

WordPress uses an indeterminate set of URLs and so it is important to have a clear partition between that and the set of URLs available to Django. The best solution is to place WordPress into a subdirectory (which is surprisingly easy).

For example:

server {
    ...
    # existing Django configuration
    ...

    location = / {
        return $scheme://$host/blog/;
    }
    location ^~ /blog {
        alias /path/to/wordpress;

        index index.php;
        if (!-e $request_filename) { rewrite ^ /blog/index.php last; }

        location ~ /wp-content/uploads/ { expires 30d; }

        location ~ \.php$ {
            if (!-f $request_filename) { rewrite ^ /blog/index.php last; }

            include       fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            ...
        }
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
            if (!-f $request_filename) { rewrite ^ /blog/index.php last; }
            expires 30d; 
        }
    }
}

You will need to set the Site and Home URLs. See this document for details.

See this document for more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!