【问题标题】:nginx multiple domain virtual host configurationnginx多域虚拟主机配置
【发布时间】:2011-02-22 18:40:21
【问题描述】:

为了方便起见,我正在设置具有多个域或通配符支持的 nginx,而不是设置 50 多个不同的可用站点/* 文件。希望这足以向您展示我正在尝试做的事情。有些是静态网站,有些是动态的,通常安装了 wordpress。

如果存在 index.php,一切都会按预期进行。

如果请求的文件不存在 (missing.html),由于重写,会给出 500 错误。记录的错误是:

*112 处理时重写或内部重定向循环“/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/ index.php/index.php/missing.html"

我目前使用的基本nginx配置是:

`

listen 80 default;
server _;

...

location / {
    root /var/www/$host;

    if (-f $request_filename) {
            expires max;
            break;
    }

    # problem, what if index.php does not exist?

    if (!-e $request_filename) {
            rewrite ^/(.*)$  /index.php/$1 last;
    }
}

...

`

如果 index.php 不存在,并且文件也不存在,我希望它出现错误 404。目前,nginx 不支持多条件 if 或嵌套 if,所以我需要一个解决方法。

【问题讨论】:

  • 你是否在重写中尝试了“break”而不是“last”?
  • 不,但我现在能够使用 try_files 而不是 if/rewrite 条件让它工作。 try_files $uri $uri/ /index.php$uri @404; 如果 index.php 不存在,它将转到位置 @404
  • try_files 是解决此类问题的建议方法,因为 if 表现不佳,不鼓励使用。您可以直接在try_files 中指定返回状态,而不是指定位置:try_files $uri $uri/ /index.php$uri =404;

标签: nginx http-status-code-404


【解决方案1】:
if ($_SERVER['HTTP_HOST'] == 'desideshat.com')
 {
 $vboptions['bburl'] = 'http://www.desideshat.com';
 }
 else
 {
 $vboptions['bburl'] = 'http://www.vedesi.com';
 } 
?>

【讨论】:

    猜你喜欢
    • 2017-09-25
    • 2012-12-24
    • 2021-05-09
    • 2011-08-17
    • 1970-01-01
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 2014-11-12
    相关资源
    最近更新 更多