我正在 AWS EC2 上的 ubuntu 14.04 服务器上使用 apache 2.4 设置 joomla 3.x 网站。仅此一点就足够了,url 重写工作正常。在为 nginx 释放端口 80 之前,我已经清除了所有 apache 问题。
尽管我才刚刚开始使用 nginx,而且这是第三次部署,但我并没有遇到什么特别的问题。基本的东西我都用得很好。
我遵循了如何锻造。设置完成后。我发现只有索引页可以正确加载,所有其他页面都index.php?
超出了域和可爱的 URL 的范围,例如
stage.domain.com/bla/bla # doesn't work
stage.domain.com/index.php?/bla/bla/ # works
我见过很多人遇到这个问题,但他们要么直接在 nginx 中托管 joomla,要么直接在 apache 中托管。在 apache 托管 joomla 之前,靠近 nginx 的情况的解决方案对我不起作用,可能我对 nginx 了解不够,所以请耐心等待。以下是配置:
#/etc/nginx/site-enabled/stage.domain.com.vhost
server {
listen 80;
server_name www.stage.domain.com stage.domain.com;
root /var/www/html/vhosts/stage.domain.com/htdocs_april;
index index.php index.html;
location / {
try_files $uri @proxy;
}
location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
expires 5d;
}
location @proxy {
proxy_pass_header Server;
proxy_pass http://127.0.0.1:8000;
include /etc/nginx/proxy_params;
}
location ~* \.php$ {
proxy_pass http://127.0.0.1:8000;
include /etc/nginx/proxy_params;
}
下面是 proxy_params(虽然这不会显示真实 IP,但在我多次尝试中,有一次我可以得到它。我将不得不在主要问题解决后解决它)
#/etc/nginx/proxy_params
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
以下是 apache2 端口配置
#/etc/apache2/ports.conf
NameVirtualHost *:8000
Listen 8000
#Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
<IfModule mod_gnutls.c>
Listen 443
</IfModule>
以下是 apache 虚拟主机
<virtualhost *:8000>
# Admin email, Server Name (domain name) and any aliases
ServerAdmin [email protected]
ServerName stage.domain.com
#RewriteEngine On
# Index file and Document Root (where the public files are located)
DirectoryIndex index.php index.html
DocumentRoot /var/www/html/vhosts/stage.domain.com/htdocs_april/
<Directory /var/www/html/vhosts/stage.domain.com/htdocs_april/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# php_flag log_errors on
#php_flag display_errors off
#php_value error_reporting 6143
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/domain_error.log
CustomLog ${APACHE_LOG_DIR}/domain_access.log combined
</virtualhost>
如果有人能指出错误配置,我将不胜感激。如前所述,仅使用 Apache 就不会出现 URL 重写问题。谢谢。
更新:
apache2 错误日志中的错误与 nginx 中的 404 无关,并且在使用 index.php?/ 时具有相同的输出:
#Info Level
[Fri Feb 27 22:51:47.862668 2015] [:error] [pid 12511] [client 127.0.0.1:58301] PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /var/www/html/vhosts/stage.domain.com/htdocs_april/templates/stage2013/functions/tpl-init.php on line 313
#Debug Level
[Fri Feb 27 22:51:47.977454 2015] [deflate:debug] [pid 12511] mod_deflate.c(849): [client 127.0.0.1:58301] AH01384: Zlib: Compressed 49347 to 11157 : URL /index.php
[Fri Feb 27 22:51:47.977925 2015] [headers:debug] [pid 12511] mod_headers.c(845): AH01502: headers: ap_headers_output_filter()
[Fri Feb 27 22:51:48.606561 2015] [authz_core:debug] [pid 12512] mod_authz_core.c(802): [client 127.0.0.1:58304] AH01626: authorization result of Require all granted: granted, referer: http://stage.domain.com/
[Fri Feb 27 22:51:48.606593 2015] [authz_core:debug] [pid 12512] mod_authz_core.c(802): [client 127.0.0.1:58304] AH01626: authorization result of <RequireAny>: granted, referer: http://stage.domain.com/
[Fri Feb 27 22:51:48.607274 2015] [deflate:debug] [pid 12512] mod_deflate.c(849): [client 127.0.0.1:58304] AH01384: Zlib: Compressed 1537 to 544 : URL /templates/stage2013/html/mod_fpss/stage5/css/template.css.php, referer: http://stage.domain.com/
[Fri Feb 27 22:51:48.607293 2015] [headers:debug] [pid 12512] mod_headers.c(845): AH01502: headers: ap_headers_output_filter()