【问题标题】:404 error on nginx location directivenginx 位置指令上的 404 错误
【发布时间】:2013-05-15 09:15:26
【问题描述】:

我正在尝试将我的 apache 重定向指令转换为 nginx 指令,目前我有以下指令:

server {
  listen          80;
  index           index.php index.html;
  server_name     myvisit_head;
  root            /var/www/mv/head/myvisit/;
  access_log      /var/log/nginx/myvisit-access.log;
  error_log       /var/log/nginx/myvisit-error.log;

  # Use gzip compression
  # gzip_static       on;  # Uncomment if you compiled Nginx using --with-http_gzip_static_module
  gzip                on;
  gzip_disable        "msie6";
  gzip_vary           on;
  gzip_proxied        any;
  gzip_comp_level     5;
  gzip_buffers        16 8k;
  gzip_http_version   1.0;
  gzip_types          text/plain text/css application/json application/x-javascript text/xml application/$

  # error pages
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /var/www;
  }

  # Deny access to hidden files
  location ~* /\.ht {
    deny            all;
    access_log      off;
    log_not_found   off;
  }

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~* /myvisitv3 {
    rewrite /(myvisitv3|myvisitV3|myVisitv3|myVisitV3)([-_])(.*).(html|php)$ /myvisitv3.php?libAdresse=$3 break;
  }

  # Pass PHP scripts on to PHP-FPM
  include global/php-fpm.conf;
  location ~* \.php$ {
    try_files       $uri /index.php;
    fastcgi_index   index.php;
    fastcgi_pass    php5-fpm-sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param   PHP_VALUE          "auto_prepend_file=/var/www/profile/external/header.php \n
                                        auto_append_file=/var/www/profile/external/footer.php";
    include /etc/nginx/fastcgi_params;
  }
}

但是当我尝试访问该 url 时,我得到一个 404 not found 错误。 我已经尝试过使用 location 和 request_uri 指令,但结果是一样的 这是我的 apache 规则:

RewriteEngine on
RewriteRule ^(myvisitv3|myvisitV3|myVisitv3|myVisitV3)([-_])(.*).(html|php)$    myvisitv3.php?libAdresse=$3 [L,QSA]
RewriteRule ^(openVisit|openvisit).(html|php)$                                  openvisitv3.php             [L,QSA]
RewriteRule ^(favicon).(ico|png|bmp|jpg)$                                       web/img/favicon.ico         [L,QSA]

【问题讨论】:

  • 您介意我们只使用不区分大小写的匹配吗?

标签: redirect nginx location


【解决方案1】:

这些规则使用不区分大小写的匹配来省去我们处理这么多情况的麻烦。

location ~* /myvisitv3[-_](.*)\.(?:html|php) {
    try_files $uri $uri/ /myvisitv3.php?libAdresse=$1;
}

location ~* /openvisit\.(?:html|php)$ {
    try_files $uri $uri/ /openvisitv3.php;
}

location ~* /favicon\.(?:ico|png|bmp|jpg)$ {
    try_files $uri $uri/ /web/img/favicon.ico;
}

【讨论】:

  • 仍然得到“ 2013/05/15 15:23:35 [错误] 5105#0: *280 open() "/var/www/mv/head/myvisit/myvisitv3-etab" 失败(2:没有这样的文件或目录),客户端:192.168.5.8,服务器:myvisit,请求:“HEAD /myvisitv3-etab HTTP/1.1”,主机:“myvisit””错误:/
  • 实际上我已经尝试过了:重写 ^/myvisitv3[-_](.*)(?:html|php)$ /myvisitv3.php?libAdresse=$1 last;它有效,但我想保持不敏感的匹配
  • 我忘记了第一个 try_files 的前导斜线可能是这个原因?
  • 你提到的错误/var/www/mv/head/myvisit/myvisitv3-etab不存在,这个的实际路径是什么?你在配置中定义了root 吗?
  • 根是在我在帖子中写的配置文件中定义的(问题是重定向失败,所以'etab'应该是第一个$_GET参数留在url中
猜你喜欢
  • 2018-12-03
  • 1970-01-01
  • 1970-01-01
  • 2012-11-09
  • 1970-01-01
  • 1970-01-01
  • 2018-04-01
  • 2013-12-21
  • 1970-01-01
相关资源
最近更新 更多