wordpress - 使用 nginx 为 flask 应用程序启用 wordpress

标签 wordpress nginx flask

是否可以使用 nginx 在现有 Flask 应用程序的/blog 上启用 wordpress?这是我一直在使用但没有得到任何结果的配置。我可以让 flask 或 wordpress 通过 nginx 工作,但是
1)不同时 2) 不是启用了/blog 选项的wordpress(wordpress 工作在/但不是/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;
    }
}

我看过a link但解决方案对我不起作用。此外,当我使用/blog 时,它默认为 --prefix 位置,所以不确定如何更改它 - a link

我想做的事情可行吗?或者我一直都很无知。

最佳答案

要在 /blog 前缀下运行 WordPress,并假设它安装在具有相同名称的目录中,您将 root 设置为上面的目录。

对属于 WordPress 的任何内容使用 ^~ 修饰符和嵌套位置 block 。参见 this document了解详情。

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

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

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

以下行与 WordPress 或 flask 无关。如果文件存在,则为指向文件所在位置的 root 设置一个值。

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

关于wordpress - 使用 nginx 为 flask 应用程序启用 wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57322478/

相关文章:

python - 使用 HTML 模板在 python 中发送电子邮件

python - 在 Flask SQLAlchemy 关联表中保存重复条目

jquery - 如何从响应式设计中删除 slider

php - Woocommerce - 当购物车中没有任何内容时 wc_add_notice() 不添加到 session

Wordpress Woocommerce - REST API 限制最多 100 个对象

Phpinfo() 在 NginX 上更新后显示旧的 PHP 版本

docker - Nginx-从Http到Https的配置导致无限重定向

ssl - 使用 Nginx 的 Play Framework 2.3.x 中的 TLS 1.2 实现

python - 无法在 Heroku 应用程序上访问 Postgres DB

javascript - ajax post 调用后 $_POST 为空