我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
对于CentOS、Ubuntu和Fedora,默认目录为/usr/share/nginx/html
其他回答
正如这里的大多数用户所说,它是在这个路径下:
/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/;
}
你可以简单地将nginx的根文件夹映射到你的网站的位置:
nano /etc/nginx/sites-enabled/default
在默认文件中,在服务器标签中寻找根,并更改网站的默认文件夹,例如,我的网站是在/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实际上非常快!
在Ubuntu中, Nginx默认根目录位置为/usr/share/nginx/html
转储配置:
$ nginx -T
...
server {
...
location / {
root /usr/share/nginx/html;
...
}
...
}
你得到的可能是不同的,因为它取决于你的nginx是如何配置/安装的。
引用:
-T选项 -T选项
更新:关于是否/何时将-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
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;
}
根节点是默认位置。