【问题标题】:install postfixadmin in a subfolder of a domain in nginx在 nginx 的域的子文件夹中安装 postfixadmin
【发布时间】:2018-09-07 18:10:57
【问题描述】:

我需要将postfixadmin 安装为 nginx 中托管的域的子文件夹。

换句话说,我正在尝试使用 http://example.com/postfixadmin 访问 postfixadmin

从物理上讲,网站的内容是这样存储的:

  • example.com 站点位于 /var/www/example
  • /var/www/postfixadmin 中的 Postfixadmin 文件

我已尝试在 example.com 的 server 部分添加此内容:

location ~ /posfixadmin/ {
    root /var/www;
    index index.php;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }

上面的部分工作,php脚本正确执行,但在/var/www/postfixadmin/css/var/www/postfixadmin/images下找到的css和图像文件没有加载。

我已经检查了生成的 html 代码,并且 postfixadmin 中的 css 和图像文件的链接是使用相对路径调用的,如下所示:

href="css/default.css"

我认为 nginx 试图从 http://example.com/css 而不是 http://example.com/postfixadmin/css 获取 css 文件,这就是它失败的原因,我尝试过这样的事情:

 location /postfixadmin/css/ {
    root /var/www/postfixadmin;
  }

但上述方法不起作用。

知道如何解决这个问题吗?提前致谢!

【问题讨论】:

    标签: nginx subdirectory


    【解决方案1】:

    我知道这是一个老话题,但仍然:不要在“位置”块中使用“根”。来源:https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

    目前这对我来说适用于当前的 PostfixAdmin 3.2(它将所有面向公众的东西都移到了“public”子目录中)。请注意,我已在别处定义了 fastcgi_pass,因此该位不直接适用。

    location /postfixadmin {
        alias /usr/local/www/postfixadmin/public;
    
        location ~ ^(.+\.php)(.*)$ {
           fastcgi_pass   php;
           fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME $request_filename;
           include        fastcgi_params;
    
           fastcgi_split_path_info ^(.+\.php)(.*)$;
           fastcgi_param PATH_INFO $fastcgi_path_info;
           fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    
           fastcgi_read_timeout 180;
           fastcgi_buffers 4 256k;
           fastcgi_buffer_size 128k;
        }
    
        location ~ \.php {
           include        /usr/local/etc/nginx/fastcgi_params;
           fastcgi_param  SCRIPT_FILENAME $request_filename;
           fastcgi_pass   php;
           fastcgi_index  index.php;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-14
      • 2015-09-11
      • 1970-01-01
      • 2019-08-27
      • 2017-05-30
      • 2012-07-14
      • 2019-07-04
      相关资源
      最近更新 更多