我正在尝试设置一个包含 3 种不同类型内容的 nginx 服务器:
- 主网站,在 CodeIgniter 上运行
- 子文件夹中的问答论坛
/qa
(在 Question2Answer 上运行) - 静态文件(在不同的位置,包括
/qa
)
我遇到了各种麻烦。我当前的配置(在服务器块内)是:
# Q2A
if ($request_uri ~* "^/qa/") {
rewrite ^/qa/(.*)$ /qa/index.php?qa-rewrite=$1 last;
}
# CI
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?$1 last;
}
location / {
index index.php index.html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_cache one;
fastcgi_cache_key $scheme$host$request_uri;
fastcgi_cache_valid 200 302 304 5m;
fastcgi_cache_valid 301 1h;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/site$fastcgi_script_name;
fastcgi_param HTTPS off;
}
除了这些问题之外,这主要是有效的:
- 正在解析/执行对我的应用程序文件夹中的 PHP 文件的请求。显然,由于这没有通过 CI 应用程序,因此会导致错误(未找到变量等)。
- 文件夹内的所有静态文件
qa
都被传递给 Q2A 应用程序,而不是作为静态文件提供
我已经尝试了很多不同的东西,我已经记不清了,比如使用类似的位置块location ~* ^/qa/ {}
和各种排列try_files
但没有运气。我还尝试在 nginx 站点上修改这个 Wordpress 示例。它们中的大多数都以/qa/
返回 404 结束。一些方法导致服务器提供原始 PHP 代码!
任何人都可以帮助设置正确的方法吗?