[英]Apache + Nginx reverse proxy not serving index.php by default
我有一堆可以很好地与 nginx + php-fastcgi 配合使用的网站,我对那里没有任何抱怨! 唯一不起作用的是名为 Gallery3 的 PHP 画廊应用程序。 遗憾的是,我必须在此应用程序中使用 Apache。 我遇到的问题如下:
gallery.wfto.cc -- 不起作用(下载包含 index.php 的 PHP 代码的未命名文件,因为它没有被解析)
gallery.wfto.cc/ -- 不起作用(同样的事情)
gallery.wfto.cc/index.php -- 不起作用(同样的事情)
gallery.wfto.cc/index.php/ -- 有效。
gallery.wfto.cc:9001(所有变体)——作品。
我不知道发生了什么。 我在下面包含了我的大部分配置。 /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>
在 apache conf 中添加:
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
我不知道从什么时候开始工作,但是如果您要更改服务器配置,请确保完全清除浏览器的缓存。
我知道这是一个古老的线程,但由于Gallery3 已经复兴,对于那些在谷歌上搜索解决方案并在此处找到您的问题的人来说,可能值得添加另一个更新的答案。
@jonmiller的以下解决方案有效: http : //jonamiller.com/2015/02/15/gallery3-on-nginx/
因为互联网变化无常,站点来来去去(他的博客只有 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
}
}
}
根据 Jon Miller 的说法,使上述所有工作正常进行的真正技巧是更改application/config/config.php
上的一行:
$config["index_page"] = "";
免责声明:我已将上述解决方案(应归功于 Jon Miller)作为功能请求发布在 GitHub 上的 Gallery the Revival 官方存储库中,以包含在文档中(README.md,一个单独的文件,等等),因为它很重要让 Gallery3 管理员知道他们现在可以在nginx
和(至少)PHP 7.4 下nginx
它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.