使用Nginx在Flask应用程序中启用Wordpress [英] Enabling wordpress with a flask app using nginx

查看:28
本文介绍了使用Nginx在Flask应用程序中启用Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Nginx在现有Flask应用程序的/blog上启用wordpress?这是我一直在使用的配置,但无法使用它.我可以通过烧瓶或Wordpress来通过Nginx工作,但
1)不能同时使用2)不是在启用/blog选项的情况下使用wordpress(wordpress在/上有效,但在/blog上无效)

Is it possible to enable wordpress on /blog of an existing flask application using nginx? Here is the config i've been working with but not getting anywhere with it. I can get either flask or wordpress to work through nginx but
1) not both at the same time 2) not wordpress with /blog option enabled (wordpress works at / but not /blog)

server {
    listen 80;
    server_name 0.0.0.0; 

#### if I enable the flask app, the blog doesn't work, so how can I keep this as well as add /blog ####
    # location / {
        #   include uwsgi_params;
        #   uwsgi_pass unix:/var/www/html/cr_webapp/my_app.sock;
    #}

#### if I change / to /blog, it starts looking in /usr/share/nginx/html location ####
    location = / {
        #root /var/www/html/blog;
        index index.php;
        try_files $uri $uri/ /blog/index.php?q=$uri?$args;
    }

    location = /favicon.ico {
        root /var/www/html/blog;
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        root /var/www/html/blog;
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ \.php$ {
        root /var/www/html/blog;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        root /var/www/html/blog;
        expires max;
        log_not_found off;
    }
}

我查看了链接但该解决方案对我不起作用.另外,当我使用/blog时,它默认为--prefix位置,所以不确定如何更改它-

I've looked at a link but the solution didn't work for me. Also, when I use /blog, it defaults to a --prefix location, so not sure how I can change that - a link

我想做的是可能的吗?还是我一直都无知.

Is what I am trying to do possible? or i've been ignorant this whole time.

推荐答案

要在/blog 前缀下运行WordPress,并假设其安装在具有相同名称的目录中,请设置 root 到上面的目录.

To run WordPress under the /blog prefix, and assuming that it's installed in a directory with the same name, you set root to the directory above.

使用 ^〜修饰符,并为属于WordPress的任何内容嵌套位置块.有关详细信息,请参见本文档.

Use the ^~ modifier, and nested location blocks for anything that belongs to WordPress. See this document for details.

location ^~ /blog {
    root /var/www/html;
    index index.php;
    try_files $uri $uri/ /blog/index.php?q=$uri?$args;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    }
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;
    }
}

假设您现有的烧瓶配置有效,则这些行应该没问题:

Assuming that your existing flask configuration works, these lines should be fine:

location / {
    include uwsgi_params;
    uwsgi_pass unix:/var/www/html/cr_webapp/my_app.sock;
}

以下几行与WordPress或flask不相关.如果文件存在,请为 root 设置一个值,该值指向文件所在的位置.

The following lines are unrelated to WordPress or flask. If the files exist, set a value for root which points to where the files are located.

location = /favicon.ico {
    log_not_found off;
    access_log off;
}
location = /robots.txt {
    log_not_found off;
    access_log off;
}

这篇关于使用Nginx在Flask应用程序中启用Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆