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

前端 未结 1 1202
耶瑟儿~
耶瑟儿~ 2020-12-20 03:05

I have a Django app that is running on a domain e.g. www.example.com

I want to create a Wordpress landing page, and point this landing page to the home url www.examp

相关标签:
1条回答
  • 2020-12-20 03:36

    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.

    0 讨论(0)
提交回复
热议问题