【问题标题】:Enabling wordpress with a flask app using nginx使用 nginx 使用烧瓶应用程序启用 wordpress
【发布时间】:2019-08-02 08:19:24
【问题描述】:

是否可以使用 nginx 在现有烧瓶应用程序的 /blog 上启用 wordpress?这是我一直在使用但没有得到任何结果的配置。我可以让烧瓶或 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

我正在尝试做的事情可能吗?或者我一直无知。

【问题讨论】:

    标签: wordpress nginx flask


    【解决方案1】:

    要在 /blog 前缀下运行 WordPress,并假设它安装在同名目​​录中,请将 root 设置为上述目录。

    使用^~ 修饰符,并为属于 WordPress 的任何内容嵌套位置块。详情请见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;
        }
    }
    

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

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

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

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

    【讨论】:

    • 哇!非常感谢你!这启用了博客主页,但 /blog/wp-admin 没有出现。 /wp-admin 只运行博客。是否有通配符或某种方法可以启用 wordpress 的管理页面?该页面被重定向到192.168.1.106/…
    • 并且明确地去 blog/wp-login 会打开登录页面但没有登录(点击登录后 404)。会不会是 wordpress mysql 数据库中的设置?
    • WordPress 需要配置正确的路径(参见Changing The Site URL)。
    猜你喜欢
    • 2012-11-19
    • 2017-12-25
    • 2018-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多