Nginx:在Symfony2应用程序的子文件夹中运行wordpress [英] Nginx: running wordpress in subfolder of a Symfony2 app

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

问题描述

我运行带有nginx的Symfony2应用程序,并希望将wordpress安装集成到公共Web文件夹的子文件夹中.

I run a Symfony2 app with nginx and want to integrate a wordpress installation in a subfolder of the public web-folder.

示例:

http://www.example.com          -> Symfony 2
http://www.example.com/magazin  -> Wordpress

有了Symfony应用程序的原始nginx配置,我可以成功地向wordpress的起始页面以及整个管理区域(包括插件安装等)发出请求.

With the origin nginx configuration of the Symfony app i can sucessfully make requests to the start-page of wordpress and also the whole admin-area including plugin installation and so on.

但是由于我将wordpress配置为对帖子使用自定义url方案年/月/标题",所以请求最终以404结尾.我发现,不是wordpress是获取请求的应用程序,而是symfony ,这当然不知道该怎么办. wordpress为帖子创建的URL是正确的(例如 http://www.example.com/magazin/2015/12/my-interesing-post ).

But since i configured wordpress to use a custom url scheme "year/month/title" for the posts, the request ends up in a 404. I figured out, that not wordpress is the application who gets the request, but symfony, which certainly doesnt know what to do here. The URL that wordpress creates for a post, is correct (e.g. http://www.example.com/magazin/2015/12/my-interesing-post).

是否可以扩展nginx配置,以处理特定文件夹"/magazin/"下的所有请求,如果可以,怎么办?

Is it possible, to extend the nginx configuration in a way to handle all requests below the specific folder "/magazin/" and if so, how?

这是我的nginx配置,目前仅处理Symfony2应用程序:

This is my nginx configuration, which currently handles only the Symfony2 application:

server {
  listen *:80;
  server_name           www.example.de;


  index  app.php index.php index.html;

  access_log            /var/log/nginx/www.example.de.access.log combined;
  error_log             /var/log/nginx/www.example.de.error.log;

  location ~ \.php$ {

    root          /data/www/www.example.de/current/web;
    include       /etc/nginx/fastcgi_params;
    try_files     $uri $uri/ /app.php?$query_string;

    fastcgi_pass  unix:/var/run/php5-fpm.sock;
    fastcgi_index app_prod.php;
    fastcgi_param X_FORWARD_PORT "80";
    fastcgi_param CUSTOMER_ENV customer_default;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi_params;
  }

  location / {

    root      /data/www/www.example.de/current/web;
    index     app.php index.php index.html;
    try_files $uri $uri/ /app.php?$query_string;
  }
}

推荐答案

除了马尔科姆斯的解释,这应该可以完成工作:

Extending to malcolms explanation, this should do the work:

(如果您的日志显示默认的nginx目录位于路径前面,则只需再次定义根目录)

(If your log says that the path of the default nginx dir is prepended, you just have to define the root directory again)

location /magazin {
    root      /data/www/www.example.de/current/web;
    index     index.php;
    try_files $uri $uri/ /magazin/index.php?q=$uri;
}

此外,我不太确定,但我建议将此位置块插入可能提取此路线的其他任何位置块之前(位置/magazin和之后的位置/).

Additionally, I'm not pretty sure but I would suggest to insert this location block before any other location block that could fetch this route (location /magazin and afterwards location /).

这篇关于Nginx:在Symfony2应用程序的子文件夹中运行wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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