NGinx默认公共www位置?

279 nginx

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

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

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

小智 412

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

编辑:

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

  • Ubuntu上的nginx 1.4.1位于/ usr/share/nginx/html中 (107认同)
  • ubuntu 16 /var/www/html/index.nginx-debian.html (6认同)
  • 刚刚确认在CentOS 7.0上,它也是/ usr/share/nginx/html (4认同)
  • Debian apt-get,检查/ etc/nginx/available-sites/default,我在那里找到了路径. (2认同)

Gna*_*foz 154

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

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

由于root选项默认为html,这将,当然,导致/usr/local/nginx/html作为回答你的问题.

但是,如果您以任何其他方式安装了nginx,则所有投注均已关闭.您的分发可能使用完全不同的默认路径.学习弄清楚你的选择分配用于什么样的默认值是另一项任务.

  • 您可以提示您可以使用"nginx -V"(大写V)来发现用于编译nginx的配置参数. (28认同)
  • 这还取决于安装所在的操作系统,对于Amazon Linux,目录是:/ usr/share/nginx/html (5认同)
  • --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 文件优先于普通的默认文件。请务必检查这两个配置文件,否则您可能使用了错误的根目录。 (3认同)
  • `nginx -V 2>&1 | grep --color -o -e '--prefix=[^[:space:]]\+'` 为您提供 nginx HOME。 (3认同)

Bab*_*ils 60

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;
        }
Run Code Online (Sandbox Code Playgroud)

根是默认位置.

  • 在CentOS中,我发现没有/ etc/nginx/sites-enabled /文件夹.有/etc/nginx/conf.d/,有两个文件server.conf和virtual.conf有这个服务器的详细信息.你也可以留意这一点. (5认同)
  • 该答案仅适用于Debian。 (2认同)

小智 37

'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
Run Code Online (Sandbox Code Playgroud)

--prefix值是问题的答案.对于根上面的示例是/ var/lib/nginx

  • 我最喜欢你的答案.为你投票 (5认同)

fre*_*gnu 25

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

/usr/local/var/www
Run Code Online (Sandbox Code Playgroud)

所以:

root html
Run Code Online (Sandbox Code Playgroud)

手段

root /usr/local/var/www/html
Run Code Online (Sandbox Code Playgroud)

没有html目录,因此必须手动创建.

  • "brew info nginx"给出了输出中列出的docroot.但是在nginx配置中指定"root html"会更改该nginx配置的docroot. (3认同)
  • 在我的brew安装中,Cellar目录是一个符号链接:`/usr/local/Cellar/nginx/1.12.0_1/html - > ../../../ var/www /`和`nginx -V`显示:`--prefix =/usr/local/Cellar/nginx/1.12.0_1`所以`root html`是通过该链接重定向的. (2认同)

Waq*_*qas 20

您只需将nginx的根文件夹映射到您网站的位置即可:

nano /etc/nginx/sites-enabled/default
Run Code Online (Sandbox Code Playgroud)

默认文件中,查找服务器标签中的根目录并更改您网站的默认文件夹,例如我的网站位于/ var/www

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www; <-- Here!
...
Run Code Online (Sandbox Code Playgroud)

当我评估nginx,apache2和lighttpd时,我将所有这些映射到位于/ var/www的网站.我发现这是有效评估的最佳方式.

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

例如

service apache2 stop
service nginx start
Run Code Online (Sandbox Code Playgroud)

顺便说一下,nginx实际上非常快!


Dig*_*ite 18

正如大多数用户所说的那样,它正是在这条道路上:

/usr/share/nginx/html
Run Code Online (Sandbox Code Playgroud)

这是默认路径,但您可以创建自己的路径.

您只需要在Web服务器根树中创建一个并为其授予一些权限"not 0777",并且仅为一个用户提供,并且仅对该用户可见,但路径末尾的路径末尾是可见的是您的文件和文件夹将由公众查看.

例如,你可以这样做一个:

home_web/site1/public_html/www/
Run Code Online (Sandbox Code Playgroud)

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

 server {
    listen  80;
        server_name  yoursite.com;

root /home_web/site1/public_html/www/;
}
Run Code Online (Sandbox Code Playgroud)


Ja͢*_*͢ck 11

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

/usr/local/nginx/html
/usr/nginx/html
Run Code Online (Sandbox Code Playgroud)


Dim*_*Dak 10

对于Ubuntu和docker镜像:

 /usr/share/nginx/html/
Run Code Online (Sandbox Code Playgroud)


Tha*_*wda 9

确保可以查看nginx配置文件。对于您的计算机上配置的任何内容,此命令都会显示:

cat /etc/nginx/sites-enabled/default |grep "root"
Run Code Online (Sandbox Code Playgroud)

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


小智 9

运行命令 nginx -V 并查找--prefix.使用该条目查找默认路径.


rub*_*cks 8

转储配置:

$ nginx -T
...
server {
    ...
    location / {
        root   /usr/share/nginx/html;
        ...
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

您得到的可能会有所不同,因为它取决于您的nginx配置/安装方式.

参考文献:

更新:关于是否/何时-T添加选项的问题存在一些混淆nginx.vl-homutov于2015年6月16日在手册页中对此进行了记录,该手册成为v1.9.2版本的一部分.它甚至在发行说明中也有提及.该-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
Run Code Online (Sandbox Code Playgroud)


小智 8

在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;
}  
Run Code Online (Sandbox Code Playgroud)


Muc*_*caP 8

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


小智 7

对于AWS EC2 Linux,您将在这里找到:

/usr/share/nginx
Run Code Online (Sandbox Code Playgroud)


jbo*_*les 5

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

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

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


Edu*_*nis 5

在我的情况下它是在 /usr/share/nginx/html

您可以尝试通过执行搜索来查找

find / -name html
Run Code Online (Sandbox Code Playgroud)


Yus*_*him 5

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

yusuf@yusuf-he:/usr/share/nginx/html$ pwd
/usr/share/nginx/html
yusuf@yusuf-he:/usr/share/nginx/html$
Run Code Online (Sandbox Code Playgroud)


Dyl*_*n B 5

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

查找/ -name nginx


小智 5

*默认页面分配在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;
    }
}
Run Code Online (Sandbox Code Playgroud)

*默认配置服务器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;
#   }
#}
Run Code Online (Sandbox Code Playgroud)

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