debian – 具有多个位置的nginx服务器配置不起作用

我一直试图让这个工作几个小时!

我想建立一个简单的Web服务器.我的网络文件应该在/ var / www中.我也想拥有PHPmyadmin.我创建了一个目录/ var / PHPmyadmin.现在我想以标准方式访问普通的Web文件.
例如:文件/var/www/test.PHP应该可以通过http://localhost/test.PHP访问.
PHPmyadmin部分应该像这样访问:http:// localhost / PHPmyadmin.使用下面的配置我得到404.也使用此URL:http://localhost/PHPmyadmin/index.PHP

为此,我在Nginx的sites-availble文件夹中创建了这个文件

server {
  listen 80; ## listen for ipv4; this line is default and implied
  listen [::]:80 default_server ipv6only=on; ## listen for ipv6

  root /var/www;
  index index.html index.htm index.PHP;

  try_files $uri $uri/ $uri/index.html $uri/index.htm $uri/index.PHP;

  # This didn't work
  location /PHPmyadmin/ {
     alias /var/PHPmyadmin;
  }

  # And this did neither. (Never used both at the same time!)
  location /PHPmyadmin/ {
     root /var;
  }

  location ~ \.PHP${
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in PHP.ini

    # With PHP5-cgi alone:
    #fastcgi_pass 127.0.0.1:9000;
    # With PHP5-fpm:
    fastcgi_pass unix:/var/run/PHP5-fpm.sock;
    fastcgi_index index.PHP;
    include fastcgi_params;
  }

  location ~ /\.ht {
    deny all;
  }
}

我究竟做错了什么?

编辑:

有趣的是,这是有效的(根目录工作(http:// localhost)):

  root /var/www/htdocs;

  index index.PHP index.html index.htm;

  location /PHPmyadmin/ {
    root /var/www/PHPmyadmin;
  }

而这不是:

  index index.PHP index.html index.htm;

  location / {
    root /var/www/htdocs;
  }

  location /PHPmyadmin/ {
    root /var/www/PHPmyadmin;
  }

PHPmyadmin仍然无法正常工作!

解决方法:

您的目标是将您的“常规”Web文件PHPMyAdmin安装完全分开.

应该强调的是,Nginx中的每个服务器配置都可以(并且应该)只有一个webroot.话虽这么说,这些是你的选择:

>在您的webroot下的目录中安装PHPMyAdmin,在您的情况下是/ var / www / PHPmyadmin.它可以通过http:// localhost / PHPmyadmin访问

这是最简单的配置,为了完整起见,我将它包含在这里(以及来自搜索引擎的人员).
>在webroot之外的目录中安装PHPMyAdmin,然后在指向该目录的webroot中创建一个名为PHPmyadmin的符号链接.在这种情况下,您需要确保在服务器配置中指定了disable_symlinks off.
>您可以通过创建在不同端口上侦听的2个服务器配置,具有不同的webroot并通过proxy_pass指令进行通信来实现在同一vhost上的分离.这种配置的基本概述如下:

server {
    listen   80;
    server_name localhost;
    root /var/www/htdocs;
    index index.PHP index.html index.htm;

    location /PHPmyadmin {
        proxy_pass http://127.0.0.1:8080/;
    }

    # ...Add more location directives, PHP support, etc...
}

server {
    listen 8080;
    server_name localhost;
    root /var/www/PHPmyadmin;
    index index.PHP index.html index.htm;

    # ...Specify additional location directives, PHP support, etc...
}

在这种情况下,对PHPMyAdmin的所有请求将透明地传递到侦听端口8080的服务器实例,通过端口80上侦听的服务器实例中的/ PHPmyadmin位置.
>最后,您可以通过创建在同一端口上侦听但具有不同server_name指令和不同根位置的2个服务器配置来实现在不同虚拟主机上的分离.例如,像这样的基本轮廓:

server {
    listen   80;
    server_name dev.local;
    root /var/www/htdocs;
    index index.PHP index.html index.htm;

    # ...Add more location directives, PHP support, etc...
}

server {
    listen   80;
    server_name PHPmyadmin.local;
    root /var/www/PHPmyadmin;
    index index.PHP index.html index.htm;

    # ...Specify additional location directives, PHP support, etc...
}

然后,您可以继续将以下条目添加到/ etc / hosts中:

127.0.0.1    dev.local
127.0.0.1    PHPmyadmin.local

然后您可以通过http://dev.local和您的PHPMyAdmin实例通过http://PHPmyadmin.local访问您的文件.显然,从您的本地工作站.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...