【问题标题】:Nginx working with apache-like locationsNginx 使用类似 apache 的位置
【发布时间】:2017-02-20 23:23:23
【问题描述】:

我正在尝试将我的个人服务器从 apache 迁移到 nginx,但我无法让该位置正常工作。

我的服务器有几个应用程序,可以从根目录中获得一些 /something,例如 url.com/git url.com/mediaWiki、url.com/vnstat url.com/redmine

在 apache 中,每个应用都有一堆配置文件:

redmine.conf

<Location "/redmine">
    Options none
    Require all granted

    PassengerEnabled On
    RailsBaseURI /redmine
    RailsEnv production
</Location>

vnstat_php.conf

Alias /vnstat /var/www/vnstat_php

<Directory /var/www/vnstat_php>
        DirectoryIndex index.php
        Require all granted
</Directory>

我正在尝试在 nginx 上复制它,但到目前为止我最好的尝试以一个奇怪的 url 结尾。我只管理在主 ngix 配置文件上编写的工作:

server {
    listen       8123 default_server;
    listen       [::]:8123 default_server;
    server_name  _;
    root         /var/www/html;

    location / {
    }

    location /vnstat/ {
        root   /var/www/vnstat_php/;
        index  index.php;
    }
}

根页面运行正常,但 /vnstat 链接将我发送到

2017/02/20 11:37:19 [error] 27538#0: *1 "/var/www/vnstat_php/vnstat/index.php" is not found (2: No such file or directory), client: 177.92.59.216, server: _, request: "GET /vnstat/ HTTP/1.1", host: "url.com:8123"

它正在 /var/www/vnstat_php/ 内寻找一个 vnstat 目录,而不是以 root 身份使用它。谁能指出我正确的方向?

【问题讨论】:

  • 你需要alias 而不是root。也许是like this

标签: nginx nginx-location


【解决方案1】:

http://nginx.org/en/docs/http/ngx_http_core_module.html#root 所述

文件的路径仅通过将 URI 添加到根指令的值来构建。如果必须修改 URI,则应使用 alias 指令。

你应该在这种情况下使用别名:

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

location /vnstat/ {
  alias /var/www/vnstat_php/;
}

但是将 PHP 与 nginx 一起使用,您应该考虑使用 FastCGI:https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

【讨论】:

  • 还是找错地方 open() "/var/www/html/vnstat" failed (2: No such file or directory), client: 177.92.59.216, server: _, request: “GET /vnstat HTTP/1.1”,主机:“url.com:8123”,引用者:“url.com:8123/frame.html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-01
  • 2013-05-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
相关资源
最近更新 更多