【问题标题】:NGinx Default public www location?Nginx 默认公共 www 位置?
【发布时间】:2012-05-27 08:10:30
【问题描述】:

我以前使用过 Apache,所以我知道默认的公共 Web 根通常是 /var/www/

我最近开始使用 nginx,但我似乎找不到默认的公共 Web 根目录。

在哪里可以找到 nginx 的默认公共 Web 根目录?

【问题讨论】:

    标签: nginx


    【解决方案1】:

    如果使用 apt-get 在 Ubuntu 上安装,请尝试 /usr/share/nginx/www

    编辑:

    在较新的版本中,路径已更改为: /usr/share/nginx/html

    2019 年编辑:

    也可以试试/var/www/html/index.nginx-debian.html

    【讨论】:

    • Ubuntu 上的 nginx 1.4.1 位于 /usr/share/nginx/html
    • 我刚刚在树莓派上安装了nginx,默认目录和lufix+1写的一样。在从 apt-get 下载的 raspbian 上
    • 刚刚确认在 CentOS 7.0 上也是 /usr/share/nginx/html
    • Debian apt-get,查看/etc/nginx/available-sites/default,我找到了那里的路径。
    • ubuntu 16 /var/www/html/index.nginx-debian.html
    【解决方案2】:

    如果您的配置不包含root /some/absolute/path; 语句,或者它包含使用root some/relative/path; 等相对路径的语句,则生成的路径取决于编译时选项。

    如果您downloaded 并自己编译源代码,那么可能是唯一能让您对这对您意味着什么做出有根据的猜测的情况。在这种情况下,路径将与使用的 --prefix 相关。如果您没有更改它,则默认为/usr/local/nginx。可以看到nginx是通过nginx -V编译的参数,它把--prefix列为第一个。

    由于the root directive defaults to html,这当然会导致/usr/local/nginx/html 成为您问题的答案。

    但是,如果您以任何其他方式安装 nginx,那么所有的赌注都将失败。您的发行版可能使用完全不同的默认路径。学习弄清楚你的选择分布使用什么样的默认值完全是另一项任务。

    【讨论】:

    • 您可能会提示您可以使用“nginx -V”(大写 V)来发现用于编译 nginx 的配置参数。
    • @kaufholdr 是正确的,您会发现提到的 --prefix @ Gnarfoz 看起来类似于 --prefix=/usr/share/nginx
    • 这也取决于安装在哪个操作系统,对于Amazon Linux,目录是:/usr/share/nginx/html
    • --prefix 路径并不总是正确的。在我的 debian 9 nginx 安装上,前缀路径是“/var/www/html”,但事实证明实际默认路径是“/usr/share/nginx/html”。查看 /etc/nginx/sites-available/default 中的默认配置文件显示该路径与 --prefix 路径相同。但是位于 /etc/nginx/conf.d/default.conf 的配置文件将根目录列为 /usr/share/nginx/html。 default.conf 文件优先于正常的默认文件。请务必检查两个配置文件,否则您可能使用了错误的根目录。
    • nginx -V 2>&1 | grep --color -o -e '--prefix=[^[:space:]]\+' 为您提供 nginx HOME。
    【解决方案3】:

    Debian 上默认的 Nginx 目录是/var/www/nginx-default

    您可以查看文件:/etc/nginx/sites-enabled/default

    然后找到

    server {
            listen   80 default;
            server_name  localhost;
    
            access_log  /var/log/nginx/localhost.access.log;
    
            location / {
                    root   /var/www/nginx-default;
                    index  index.html index.htm;
            }
    

    根是默认位置。

    【讨论】:

    • 在 CentOS 中,我发现没有 /etc/nginx/sites-enabled/ 文件夹。有 /etc/nginx/conf.d/ 有两个文件 server.conf 和 virtual.conf 有这个服务器的详细信息。你也可以留意一下。
    • 添加到 Nafis 的评论中,conf.d 目录下的文件名必须以 .conf 结尾,否则不会被拾取。
    • 这仅适用于启用默认站点并与请求匹配的情况。否则默认根为html
    • @OrangeDog 如何检查default site是否启用?
    • @Timo 这个答案说明了如何
    【解决方案4】:

    'default public web root' 可以从 nginx -V 输出中找到:

    nginx -V
    nginx version: nginx/1.10.1
    built with OpenSSL 1.0.2h  3 May 2016
    TLS SNI support enabled
    configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --user=nginx --group=nginx --with-ipv6 --with-file-aio --with-pcre-jit --with-http_dav_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module --with-http_auth_request_module --with-mail --with-mail_ssl_module
    

    --prefix 值是问题的答案。对于根目录上方的示例是 /var/lib/nginx

    【讨论】:

    • 是的,最好的,跨平台的。
    • 这并不总是正确的 "--prefix" 可能在某些系统上使用,但不是全部。我同意 nginx -V 为您提供了很多有助于跟踪文件位置的信息,但这取决于操作系统。 IE。在 FreeBSD 上确实不在任何“--prefix”中,而是在“/usr/local/www”中,并且在某些 linux 发行版中它也可能有所延迟。最好查看配置。
    • "--prefix" 是 GNU 标准定义的变量 - 见gnu.org/prep/standards/html_node/Directory-Variables.html
    • "--prefix" 是 GNU 标准定义的变量 - 参见 gnu.org/prep/standards/html_node/Directory-Variables.html。 nginx 遵循标准。如果您未在配置文件中定义根目录或位置(取决于 --conf-path),则前缀将显示“默认公共 Web 根目录”所在的位置。这不依赖于操作系统,尽管随操作系统分发提供的软件包也可以提供重新定义“默认公共 Web 根”的配置。
    • 所以算法:在nginx -V输出中寻找--conf-path。如果 location /root 未在配置中重新定义 - 使用 --prefix 作为“默认公共 Web 根”位置。
    【解决方案5】:

    对于 Ubuntu 和 docker 镜像:

    /usr/share/nginx/html/

    【讨论】:

    • 只是好奇,说我不知道​​,我怎么会找到正确的位置?对此有很多不同的答案
    • 据我所知,我搜索了“nginx”(类似于 find / -name nginx )并在此目录(或其子目录)中找到了出现在我的浏览器中的文档。
    【解决方案6】:

    在 Mac OS X 上,使用 brew 安装 nginx 会生成默认目录:

    /usr/local/var/www
    

    所以:

    root html
    

    意思

    root /usr/local/var/www/html
    

    没有 html 目录,所以必须手动创建。

    【讨论】:

    • +1 用于提及 macOS 和自制软件。但是,我发现虽然root htmlindex.html50x.html直接放在/usr/local/var/www中。因此,我怀疑html 文件夹的存在。你能给我一些帮助吗?
    • "brew info nginx" 给出输出中列出的 docroot。但是在 nginx 配置中指定“root html”会更改该 nginx 配置的 docroot。
    • 对于我 (MAC OS X El Capitan 10.11.5) 和 brew (1.1.5) ,目录是 /usr/local/Cellar/nginx/1.10.2_1/html 其中 1.10.2_1 是 nginx 版本。
    • 在我的 brew 安装中,地窖目录是一个符号链接:/usr/local/Cellar/nginx/1.12.0_1/html -> ../../../var/www/nginx -V 显示:--prefix=/usr/local/Cellar/nginx/1.12.0_1 所以root html 是通过该链接重定向的。
    • @iplus26 html 目录已经可用 /usr/local/Cellar/nginx/1.12.2_1/html,我认为 /usr/local/var/www 只是一个链接
    【解决方案7】:

    正如这里大多数用户所说,它在这条路径下:

    /usr/share/nginx/html
    

    这是默认路径,但您可以自己设置。

    您只需要在 Web 服务器根树中创建一个并赋予它一些“非 0777”权限,并且仅对一个用户可见,并且仅对该用户可见,但路径的结尾自结束后对所有人可见路径的名称是您的文件和文件夹将被公众查看。

    例如,您可以这样制作:

    home_web/site1/public_html/www/
    

    每当您在 Nginx 中创建虚拟主机时,您都可以自定义自己的根路径,只需在您的服务器块中添加如下内容:

     server {
        listen  80;
            server_name  yoursite.com;
    
    root /home_web/site1/public_html/www/;
    }
    

    【讨论】:

    • 是的,你是对的。我刚刚在我的 centos7 上安装了 Nginx,我注意到默认路径是 /usr/share/nginx/html/ 文件夹。是否有理由改变这条路径(出于安全或任何其他原因)?如果我将成为唯一的用户并且只在其中托管 1 个网站,是否可以将其保留在默认文件夹中?
    • 别在意我的最后一个问题。我最终为它创建了单独的文件夹,因为我认为这种方式更好,以防我将来确实想在这个设置中添加不同的虚拟主机。这种方式更容易。干杯:)
    【解决方案8】:

    您可以简单地将 nginx 的 根文件夹映射到您网站的位置:

    nano /etc/nginx/sites-enabled/default
    

    default 文件中,在 server 标签中查找 root 并更改您网站的默认文件夹,例如我的网站位于 /var/www

    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
    
            root /var/www; <-- Here!
    ...
    

    当我评估 nginx、apache2 和 lighttpd 时,我将它们全部映射到位于 /var/www 的网站。我发现这是有效评估的最佳方式。

    然后您可以启动/停止您选择的服务器,看看哪个性能最好。

    例如

    service apache2 stop
    service nginx start
    

    顺便说一句,nginx其实很快!

    【讨论】:

      【解决方案9】:

      查看 nginx 配置文件以确定。 此命令对您机器上配置的任何内容进行 greps:

      cat /etc/nginx/sites-enabled/default |grep "root"
      

      在我的机器上是:root /usr/share/nginx/www;

      【讨论】:

        【解决方案10】:

        nginx 的默认 web 文件夹取决于您的安装方式,但通常位于以下位置:

        /usr/local/nginx/html
        /usr/nginx/html
        

        【讨论】:

          【解决方案11】:

          运行命令nginx -V 并查找--prefix。使用该条目来定位您的默认路径。

          【讨论】:

            【解决方案12】:

            转储配置:

            $ nginx -T
            ...
            server {
                ...
                location / {
                    root   /usr/share/nginx/html;
                    ...
                }
                ...
            }
            

            您得到的可能会有所不同,因为这取决于您的 nginx 是如何配置/安装的。

            参考资料:

            更新:如果/何时将-T 选项添加到nginx,存在一些混淆。它在 2015 年 6 月 16 日由 vl-homutov 记录在手册页中,成为 v1.9.2 release 的一部分。甚至在the release notes 中也提到过。从那时起,-T 选项出现在每个 nginx 版本中,包括在 Ubuntu 16.04.1 LTS 上可用的选项:

            root@23cc8e58640e:/# nginx -h    
            nginx version: nginx/1.10.0 (Ubuntu)
            Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
            
            Options:
              -?,-h         : this help
              -v            : show version and exit
              -V            : show version and configure options then exit
              -t            : test configuration and exit
              -T            : test configuration, dump it and exit
              -q            : suppress non-error messages during configuration testing
              -s signal     : send signal to a master process: stop, quit, reopen, reload
              -p prefix     : set prefix path (default: /usr/share/nginx/)
              -c filename   : set configuration file (default: /etc/nginx/nginx.conf)
              -g directives : set global directives out of configuration file
            

            【讨论】:

            • 我认为此标志不存在,您可能需要更新答案
            • @ifender6445,我对你的评论感到非常困惑。我有两个对源代码行的引用,每个都显示-T 选项。您的特定安装中是否缺少 -T 选项?你能出示任何东西来证实你的主张吗?
            • 是的,可能是 nginx 的不同版本? gist.github.com/lfender6445/ed8c5e26db64eba595ae4aaf4d15ee0d
            • 我明白了。看来我使用的是旧版本的 nginx,抱歉!
            【解决方案13】:

            对于 CentOS、Ubuntu 和 Fedora,默认目录为 /usr/share/nginx/html

            【讨论】:

            • 我想要来自var/www/html的nginx root。
            【解决方案14】:

            在 Mac 上使用 brew 安装 nginx:

            /usr/local/etc/nginx/nginx.conf

            location / { 
                root   html;  # **means /usr/local/Cellar/nginx/1.8.0/html and it soft linked to /usr/local/var/www**
                index  index.html;
            }  
            

            【讨论】:

              【解决方案15】:

              对于 AWS EC2 Linux,您可以在此处找到:

              /usr/share/nginx
              

              【讨论】:

                【解决方案16】:

                请注意,nginx 服务器的默认索引页面也将显示根位置。从 Amazon Linux AMI 上的 nginx (1.4.3),您将获得以下信息:

                这是在 Amazon Linux AMI 上随 nginx 分发的默认 index.html 页面。它位于 /usr/share/nginx/html。

                您现在应该将您的内容放在您选择的位置,并在 nginx 配置文件 /etc/nginx/nginx.conf 中编辑根配置指令

                【讨论】:

                  【解决方案17】:

                  在我的例子中是/usr/share/nginx/html

                  你可以尝试通过搜索来找到

                  find / -name html
                  

                  【讨论】:

                    【解决方案18】:

                    如果您使用的是 Ubuntu 14.04,您可以在以下路径找到 nginx www 目录:

                    yusuf@yusuf-he:/usr/share/nginx/html$ pwd
                    /usr/share/nginx/html
                    yusuf@yusuf-he:/usr/share/nginx/html$
                    

                    【讨论】:

                    • 谢谢,简洁准确。有时最简单的解释就是最好的解释。
                    • 我想要来自var/www/html的nginx root。
                    【解决方案19】:

                    您可以搜索它,无论他们将它移动到哪里(系统管理员移动或更新版本的 nginx)

                    find / -name nginx

                    【讨论】:

                      【解决方案20】:

                      如果您需要找出在编译时定义的 nginx 公共根文件夹,您可以检查您的 access.log 文件。

                      1. 打开 nginx.conf
                      2. 找到 log_format 指令
                      3. log_format 的值是一个模板字符串,用于将信息写入access.log 文件。您可以将 $document_root 变量添加到此模板字符串,以将默认 www 根位置记录到文件中。

                      这是 nginx.conf 的 http 部分的示例,其中修改了 log_format 指令,在字符串开头添加了 $document_root:

                          http {
                              include       /etc/nginx/mime.types;
                              default_type  application/octet-stream;
                      
                                        ## ADD $document_root HERE ##
                              log_format  main  '$document_root $remote_addr - $remote_user [$time_local] "$request" '
                                                '$status $body_bytes_sent "$http_referer" '
                                                '"$http_user_agent" "$http_x_forwarded_for"';
                      
                              access_log  /var/log/nginx/access.log  main;
                      
                              etc. .......
                      
                      1. 然后将所有配置文件*.conf备份到conf.d目录下,并创建配置文件test.conf,内容如下:

                        server{
                            listen 80;
                            server_name localhost;
                        }
                        
                        1. 将以下行添加到 /etc/hosts 文件:127.0.0.1 localhost

                        2. 重新加载nginx配置:nginx -s reload

                        3. http://localhost发送GET请求:curl http://localhost

                        4. 查看access.log的最后一个字符串:tail -n 1 /var/log/nginx/access.log

                      这是该命令的示例输出,其中 /etc/nginx/html 是编译时定义的默认文档根目录:

                          /etc/nginx/html 127.0.0.1 - - [15/Mar/2017:17:12:25 +0200] "GET / HTTP/1.1" 404 169 "-" "curl/7.35.0" "-"
                      

                      【讨论】:

                      • 它似乎有效,但没有解决我的问题,*.knexusgroup.com 的记录在 54.235.222.119,w3.knexusgroup.com,但它没有记录任何域 .knexusgroup。 com .它适用于有正确定义根目录的地方,我无法弄清楚是什么问题,为什么我找不到与任何 ngiinx 配置不匹配的任何子域的根目录。
                      【解决方案21】:

                      你可以访问文件配置nginx,你可以看到root /path。在这 nginx apache 默认为/var/www/html

                      【讨论】:

                      • /var/www/html 是 apache 的默认 Web 根目录,而不是 nginx。
                      【解决方案22】:

                      *在 var/www/html 中分配的默认网页网页 *默认配置服务器 etc/nginx/sites/avaliable/nginx.conf

                      server {
                      
                          listen 80 default_server;
                          listen [::]:80 default_server;
                      
                          root /var/www/html;
                      
                          index index.html index.php;
                      
                          server_name _;
                      
                          location /data/ {
                              autoindex on;
                          }
                      
                          location /Maxtor {
                              root /media/odroid/;
                              autoindex on;
                      
                          }
                      
                              # This option is important for using PHP.
                          location ~ \.php$ {
                              include snippets/fastcgi-php.conf;
                              fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                          }
                      }
                      

                      *默认配置服务器 etc/nginx/nginx.conf

                      内容..

                      user www-data;
                      worker_processes 8;
                      pid /run/nginx.pid;
                      include /etc/nginx/modules-enabled/*.conf;
                      
                      events {
                          worker_connections 768;
                          # multi_accept on;
                      }
                      
                      http {
                      
                          ##
                          # Basic Settings
                          ##
                      
                          sendfile on;
                          tcp_nopush on;
                          tcp_nodelay on;
                          keepalive_timeout 65;
                          types_hash_max_size 2048;
                          # server_tokens off;
                      
                          # server_names_hash_bucket_size 64;
                          # server_name_in_redirect off;
                      
                          include /etc/nginx/mime.types;
                          default_type application/octet-stream;
                      
                          ##
                          # SSL Settings
                          ##
                      
                          ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
                          ssl_prefer_server_ciphers on;
                      
                          ##
                          # Logging Settings
                          ##
                      
                          access_log /var/log/nginx/access.log;
                          error_log /var/log/nginx/error.log;
                      
                          ##
                          # Gzip Settings
                          ##
                      
                          gzip on;
                      
                          # gzip_vary on;
                          # gzip_proxied any;
                          # gzip_comp_level 6;
                          # gzip_buffers 16 8k;
                          # gzip_http_version 1.1;
                          # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
                      
                          ##
                          # Virtual Host Configs
                          ##
                      
                          include /etc/nginx/conf.d/*.conf;
                          include /etc/nginx/sites-enabled/*;
                      }
                      
                      
                      #mail {
                      #   # See sample authentication script at:
                      #   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
                      # 
                      #   # auth_http localhost/auth.php;
                      #   # pop3_capabilities "TOP" "USER";
                      #   # imap_capabilities "IMAP4rev1" "UIDPLUS";
                      # 
                      #   server {
                      #       listen     localhost:110;
                      #       protocol   pop3;
                      #       proxy      on;
                      #   }
                      # 
                      #   server {
                      #       listen     localhost:143;
                      #       protocol   imap;
                      #       proxy      on;
                      #   }
                      #}
                      

                      默认访问日志与 ip 客户端 var/log/nginx/...

                      【讨论】:

                        【解决方案23】:

                        我在 Ubuntu 上的 nginx 是“nginx 版本:nginx/1.9.12 (Ubuntu)” 根路径是 /var/www/html/

                        Ubuntu 信息是: 没有可用的 LSB 模块。 经销商编号:Ubuntu 说明:Ubuntu 16.04 LTS 发布时间:16.04 代号:xenial

                        其实,如果你刚刚在Ubuntu上安装了nginx,那么你可以去“/etc/nginx/sites-available”查看默认文件,有一个类似“root /web/root/path/goes/”的配置这里”。这就是您要寻找的。​​p>

                        【讨论】:

                          【解决方案24】:

                          在 Ubuntu 中, Nginx 默认根目录位置为/usr/share/nginx/html

                          【讨论】:

                            【解决方案25】:

                            您可以在 /var/www/ 中找到它,这是 nginx 和 apache 的默认目录,但您可以更改它。 第 1 步转到以下文件夹 /etc/nginx/sites-available

                            步骤 2 编辑默认文件,您可以在其中找到一个服务器块,在该块下将有一个名为 root 的行,它定义了该位置。

                            【讨论】:

                              【解决方案26】:

                              在 ubuntu 19.04 中,我们在

                              上找到了它

                              /usr/share/nginx/html

                              【讨论】:

                                【解决方案27】:

                                适用于 nginx/1.4.6 (Ubuntu)

                                /etc/nginx$ cat /etc/nginx/sites-available/default | grep -i root
                                - root /usr/share/nginx/html;
                                

                                【讨论】:

                                  【解决方案28】:

                                  我在使用 nginx 运行 WordPress 网站的 Digital Ocean 上也遇到了这个问题。

                                  我的解决方案是执行以下操作:

                                  1. 使用以下内容修改/etc/nginx/nginx.conf 文件:
                                  server {
                                  root /var/www/html;
                                  }
                                  

                                  然后我不得不sudo service nginx restart

                                  nginx -V 命令还向您显示您的 nginx 配置文件所在的位置(我的指向 /etc/nginx/nginx.conf

                                  【讨论】:

                                    【解决方案29】:

                                    默认与编译nginx时configure脚本的prefix选项有关;这是来自 Debian 的一些奇怪示例:

                                    % nginx -V | & tr ' ' "\n" | fgrep -e path -e prefix
                                    --prefix=/etc/nginx
                                    --conf-path=/etc/nginx/nginx.conf
                                    --error-log-path=/var/log/nginx/error.log
                                    --http-client-body-temp-path=/var/lib/nginx/body
                                    --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
                                    --http-log-path=/var/log/nginx/access.log
                                    --http-proxy-temp-path=/var/lib/nginx/proxy
                                    --http-scgi-temp-path=/var/lib/nginx/scgi
                                    --http-uwsgi-temp-path=/var/lib/nginx/uwsgi
                                    --lock-path=/var/lock/nginx.lock
                                    --pid-path=/var/run/nginx.pid
                                    

                                    随后,root 的默认值是set to the html directory(根据documentation of the root directive),恰好在prefix 之内,可以通过从简单配置中查看$document_root 变量来验证文件:

                                    # printf 'server{listen 4867;return 200 $document_root\\n;}\n' \
                                        >/etc/nginx/conf.d/so.10674867.conf
                                    
                                    # nginx -s reload && curl localhost:4867
                                    /etc/nginx/html
                                    

                                    然而,像 Debian 这样的邪恶发行版似乎对其进行了相当多的修改,以让您更加开心:

                                    % fgrep -e root -e include /etc/nginx/nginx.conf
                                        include /etc/nginx/mime.types;
                                        #include /etc/nginx/naxsi_core.rules;
                                        #passenger_root /usr;
                                        include /etc/nginx/conf.d/*.conf;
                                        include /etc/nginx/sites-enabled/*;
                                    
                                    % fgrep -e root -e include \
                                        /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/*
                                    /etc/nginx/conf.d/so.10674867.conf:server{listen 4867;return 200 $document_root\n;}
                                    /etc/nginx/sites-enabled/default:   root /usr/share/nginx/www;
                                    /etc/nginx/sites-enabled/default:       # include /etc/nginx/naxsi.rules
                                    /etc/nginx/sites-enabled/default:   #   root /usr/share/nginx/www;
                                    /etc/nginx/sites-enabled/default:   #   include fastcgi_params;
                                    /etc/nginx/sites-enabled/default:   # deny access to .htaccess files, if Apache's document root
                                    /etc/nginx/sites-enabled/default:#  root html;
                                    /etc/nginx/sites-enabled/default:#  root html;
                                    

                                    所以,在这个 Debian 实例上,您可以看到 root 最终设置为 /usr/share/nginx/www

                                    但是正如您在通过 http 提供 $document_root 值的示例服务器配置中看到的那样,配置 nginx 非常简单,您只需一两行即可编写自己的配置,指定所需的 @987654337 @ 以满足您的确切需求。

                                    【讨论】:

                                    • root html;是什么意思,我的意思是什么是真实路径?
                                    • @RamratanGupta,您没有阅读答案吗?第一行概述了路径是相对于编译时前缀设置的。
                                    【解决方案30】:

                                    Alpine Linux 根本没有任何默认位置。文件/etc/nginx/conf.d/default.conf 说:

                                    # Everything is a 404
                                    location / {
                                        return 404;
                                    }
                                    
                                    # You may need this to prevent return 404 recursion.
                                    location = /404.html {
                                        internal;
                                    }
                                    

                                    root /var/www/localhost/htdocs 之类的行替换它们以指向您想要的目录。然后sudo service nginx restart重启。

                                    【讨论】:

                                    • 不正确。刚刚尝试了最新的nginx:alpine 图像,它提供了来自/usr/share/nginx/html 的内容。
                                    • 这听起来像是 nginx 项目制作的 Docker 镜像,恰好使用 Alpine Linux 作为底层操作系统。当您将 Alpine Linux 安装为您的主要操作系统并执行 apk add nginx 从 Alpine 自己的包管理器手动安装 nginx 时,您会得到我的回答中描述的情况(或者几个月前我尝试过的情况就是这种情况)。
                                    猜你喜欢
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 1970-01-01
                                    • 2015-08-10
                                    • 1970-01-01
                                    • 2015-03-25
                                    • 2011-02-26
                                    • 1970-01-01
                                    • 2016-11-29
                                    相关资源
                                    最近更新 更多