我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
如果你使用的是Ubuntu 14.04,你可以在以下路径找到nginx www目录:
yusuf@yusuf-he:/usr/share/nginx/html$ pwd
/usr/share/nginx/html
yusuf@yusuf-he:/usr/share/nginx/html$
其他回答
如果你需要找到编译时定义的nginx公共根文件夹,你可以检查你的access.log文件。
打开nginx.conf 找到log_format指令 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. .......
然后备份conf.d目录下的所有配置文件*.conf,并创建配置文件test.conf,如下所示: 服务器{ 听80; server_name主机; } 在“/etc/hosts”文件中增加如下一行:127.0.0.1 localhost 重载nginx配置:nginx -s重载 发送GET请求到http://localhost: curl http://localhost 查看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" "-"
你可以在nginx和apache的默认目录/var/www/中找到它,但你可以改变它。 步骤1进入“/etc/nginx/sites-available”文件夹
步骤2编辑默认文件,您可以在其中找到一个服务器块,其中将有命名为root的行,这是定义位置的内容。
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;
}
根节点是默认位置。
对于Ubuntu和docker映像:
/usr/share/nginx/html/
对于CentOS、Ubuntu和Fedora,默认目录为/usr/share/nginx/html