简体   繁体   English

Apache + Nginx 反向代理默认不提供 index.php

[英]Apache + Nginx reverse proxy not serving index.php by default

I have a bunch of sites that work great with nginx + php-fastcgi and I have no complaints there!我有一堆可以很好地与 nginx + php-fastcgi 配合使用的网站,我对那里没有任何抱怨! The only thing that doesn't work is a PHP gallery application called Gallery3.唯一不起作用的是名为 Gallery3 的 PHP 画廊应用程序。 Sadly, I have to use Apache with this application.遗憾的是,我必须在此应用程序中使用 Apache。 The problem I have is as follows:我遇到的问题如下:

gallery.wfto.cc -- Doesn't work (downloads an unnamed file containing the PHP code of index.php because it isn't getting parsed) gallery.wfto.cc -- 不起作用(下载包含 index.php 的 PHP 代码的未命名文件,因为它没有被解析)

gallery.wfto.cc/ -- Doesn't work (same thing) gallery.wfto.cc/ -- 不起作用(同样的事情)

gallery.wfto.cc/index.php -- Doesn't work (same thing) gallery.wfto.cc/index.php -- 不起作用(同样的事情)

gallery.wfto.cc/index.php/ -- Works. gallery.wfto.cc/index.php/ -- 有效。

gallery.wfto.cc:9001 (all variants) -- Works. gallery.wfto.cc:9001(所有变体)——作品。

I have no idea what is going on.我不知道发生了什么。 I included most of my configurations below.我在下面包含了我的大部分配置。 The /etc/nginx/conf.d/proxy.conf is a ... general proxy configuration, nothing special. /etc/nginx/conf.d/proxy.conf 是一个...通用代理配置,没什么特别的。

##NGINX CONFIG##
server {
    listen 80; ## listen for ipv4
    listen [::]:80 default ipv6only=on; ## listen for ipv6

    root /var/www/vhosts/wfto.cc/subdomains/gallery;

    server_name gallery.wfto.cc;
    access_log /var/log/nginx/gallery.wfto.cc.access.log;

    location / {
        proxy_pass http://127.0.0.1:9001;
        include /etc/nginx/conf.d/proxy.conf;
    }
}
## APACHE CONFIG ##
<VirtualHost *:9001>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/vhosts/wfto.cc/subdomains/gallery
        <IfModule mod_fastcgi.c>
                AddHandler php5-fcgi .php
                Action php5-fcgi /php5-fcgi
                Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
                FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
        </IfModule>
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/vhosts/wfto.cc/subdomains/gallery/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Add this in apache conf:在 apache conf 中添加:

<IfModule dir_module>
    DirectoryIndex index.php
</IfModule>

我不知道从什么时候开始工作,但是如果您要更改服务器配置,请确保完全清除浏览器的缓存。

I know this is an ancient thread, but because Gallery3 has gone through a revival , it might be worth adding another, more up-to-date answer, for those who have googled for a solution and found your question here.我知道这是一个古老的线程,但由于Gallery3 已经复兴,对于那些在谷歌上搜索解决方案并在此处找到您的问题的人来说,可能值得添加另一个更新的答案。

The following solution by @jonmiller works: http://jonamiller.com/2015/02/15/gallery3-on-nginx/ @jonmiller的以下解决方案有效: http : //jonamiller.com/2015/02/15/gallery3-on-nginx/

Because the Internet is fickle, and sites come and go (his blog only has two entries from 2015, clearly something he has not been updating...), taking into account that all credits are due to Jon Miller, here is the working configuration:因为互联网变化无常,站点来来去去(他的博客只有 2015 年的两个条目,显然他没有更新......),考虑到所有学分都归功于 Jon Miller,这里是工作配置:

server {
    server_name <gallery_url>;
    listen 80;

    root <path_to_gallery_installion>;

    access_log <path_to_log_locations>;
    error_log <path_to_log_locations>;

    index index.php;

    location / {

        location ~ /(index\.php/)?(.+)$ {
            try_files $uri /index.php?kohana_uri=$2&$args;
            location ~ /var/thumbs/.*/.album.jpg {
                # Direct access to album thumbs explicity allowed
            }
            location ~ /\.(ht|tpl(\.php?)|sql|inc\.php|db)$ {
                deny all;
            }
            location ~ /var/(uploads|tmp|logs) {
                deny all;
            }
            location ~ /bin {
                deny all;
            }
            location ~ /var/(albums|thumbs|resizes) {
                rewrite ^/var/(albums|thumbs|resizes)/(.*)$ /file_proxy/$2 last;
            }
            location ~* \.(js|css|png|jpg|jpeg|gif|ico|ttf)$ {
                try_files $uri /index.php?kohana_uri=$uri&$args;
                expires 30d;
            }
        }

        location = /index.php {
            include fastcgi_params;
            fastcgi_index index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_pass localhost:9000; // adjust as necessary
        }
    }
}

According to Jon Miller, the real trick that made all the above work correctly was to change one line on application/config/config.php :根据 Jon Miller 的说法,使上述所有工作正常进行的真正技巧是更改application/config/config.php上的一行:

$config["index_page"] = "";

Disclaimer: I have posted the above solution (with due credit to Jon Miller) as a feature request on the official repository for Gallery the Revival on GitHub for inclusion in the documentation (README.md, a separate file, whatever), since it's critical for Gallery3 admins to be aware that they now can get it working under nginx and (at least) PHP 7.4.免责声明:我已将上述解决方案(应归功于 Jon Miller)作为功能请求发布在 GitHub 上的 Gallery the Revival 官方存储库中,以包含在文档中(README.md,一个单独的文件,等等),因为它很重要让 Gallery3 管理员知道他们现在可以在nginx和(至少)PHP 7.4 下nginx它。

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

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