大网数据广告活动
服务器运维问答

Nginx redirect failure for icingaweb2

· 52CE 我爱测

I'm trying to configure IcingaWeb2 using Nginx, and having some issues with it. The suggested Icinga Nginx configuration is: location ~ ^/icingaweb2/index\.php(.*)$ { # fastcgi_pass 127.0.0.1:9000; fastcgi_pass unix:/var/run/php5…

问题原文

原帖链接 · lithiium · CC BY-SA 3.0

I'm trying to configure IcingaWeb2 using Nginx, and having some issues with it. The suggested Icinga Nginx configuration is:

location ~ ^/icingaweb2/index\.php(.*)$ {
  # fastcgi_pass 127.0.0.1:9000;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  include fastcgi_params;
  fastcgi_param SCRIPT_FILENAME /usr/share/icingaweb2/public/index.php;
  fastcgi_param ICINGAWEB_CONFIGDIR /etc/icingaweb2;
  fastcgi_param REMOTE_USER $remote_user;
}

location ~ ^/icingaweb2(.+)? {
  alias /usr/share/icingaweb2/public;
  index index.php;
  try_files $1 $uri $uri/ /icingaweb2/index.php$is_args$args;
}

This works fine, but let's the web on /icingaweb2/ while I want it on /. If I just remove icingaweb2/ from the conf, it works fine for every URL but /.

My current configuration is:

server {
    listen 443 ssl default_server;

    server_name example.com
    ssl_certificate cert_path;
    ssl_certificate_key cert_key;

    location ~ ^/index\.php(.*)$ {
      fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME /usr/share/icingaweb2/public/index.php;
      fastcgi_param ICINGAWEB_CONFIGDIR /etc/icingaweb2;
      #fastcgi_param REMOTE_USER $remote_user;
    }

    location ~ ^/(.*)? {
     alias /usr/share/icingaweb2/public;
     index index.php;
     try_files $1 $uri $uri/ /index.php$is_args$args;
    }
}

This works perfectly fine if I try, for example, to access https://example.com/dashboard but fails only for https://example.com/ with a 403 error. I have also tried to configure a specific location / {} doing a redirect o rewrite to /dashboard but still getting a 403.

Any idea of what can I try next?

已采纳解答

原帖链接 · lithiium · CC BY-SA 3.0

I fix it putting a rewrite on the second location.

location ~ ^/(.*)? {
 alias /usr/share/icingaweb2/public;
 index index.php;
 rewrite ^/$ /dashboard;
 try_files $1 $uri $uri/ /index.php$is_args$args;
}

It doesn't feel like the best... but now all is working as expected.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-07-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。