简体   繁体   English

Nginx pnp4nagios与php5-fpm

[英]Nginx pnp4nagios with php5-fpm

I have been going at this for a day now. 我现在已经在这一天了。 And I think it's time to ask for help now. 而且我认为现在是时候寻求帮助了。

I'm moving our nagios to nginx. 我正在将我的nagios移动到nginx。 I have nagios running as well as a django application I recently developed. 我有nagios运行以及我最近开发的django应用程序。 Pnp4nagios is giving me some troubles though. Pnp4nagios虽然给了我一些麻烦。 I have the following configuration in Nginx. 我在Nginx中有以下配置。

location ~ ^(/pnp4nagios/.*\.php)(.*)$ {
    root /usr/share/pnp4nagios/html;

    include /etc/nginx/fastcgi_params;
    rewrite ^/pnp4nagios/(.*)$ /$1 break;

    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param   SCRIPT_FILENAME     /usr/share/pnp4nagios/html/$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
}

This results in this: 这导致: 文件夹错了

As you can see, pnp4nagios thinks that its index.php lives in 172.16.10.28/index.php But this isn't true. 正如你所看到的,pnp4nagios认为它的index.php生活在172.16.10.28/index.php但是事实并非如此。 It is a sub-page (or whatever i should call it?). 这是一个子页面(或者我应该称之为什么?)。 I want it to point to 172.16.10.28/pnp4nagios/index.php but I have no clue how I can do this in my nginx config. 我希望它指向172.16.10.28/pnp4nagios/index.php,但我不知道如何在我的nginx配置中执行此操作。 I would prefer not to change anything in pnp4nagios. 我宁愿不改变pnp4nagios中的任何内容。 But if it's only one or a few lines it's a compromise I'm willing to make. 但如果它只是一条或几条线,那么我愿意做出妥协。 I already have an index.php in my "root" url. 我的“root”网址中已经有一个index.php。 That's why I want a subfolder. 这就是我想要一个子文件夹的原因。

The examples that have lead me to this aproach are: Example1 Example2 引导我这种方法的例子有: 例1 例2

So to recap what I want (or what I think that I need) is to go from this: img src="/index.php... to img src="/pnp4nagios/index.php... 所以回顾一下我想要的东西(或者我认为我需要的东西)就是这样: img src="/index.php... to img src="/pnp4nagios/index.php...

PS. PS。 I didn't have enough points to create a pnp4nagios tag 我没有足够的积分来创建pnp4nagios标签

This worked for me: 这对我有用:

location /pnp4nagios {
    alias /usr/share/pnp4nagios/html;
}   

location ~ ^(/pnp4nagios.*\.php)(.*)$ {
    root /usr/share/pnp4nagios/html;
    include /etc/nginx/fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info;

   fastcgi_param SCRIPT_FILENAME $document_root/index.php;
    fastcgi_pass 127.0.0.1:9000; 

}   

You've got a rewrite in your configuration that strips php4nagios path component. 您已经在配置中重写了剥离php4nagios路径组件。 Therefore it's not surprising to see the reference to /index.php . 因此,看到对/index.php的引用并不奇怪。 You should verify the resulting CGI variables using an info.php page in the appropriate directory. 您应该使用相应目录中的info.php页面验证生成的CGI变量。 The offending line is: 违规行是:

rewrite /pathinfo/(.*)/ $1 break;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM