我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
在Mac上使用brew安装nginx:
/ usr / local / etc / nginx / nginx上。
location / {
root html; # **means /usr/local/Cellar/nginx/1.8.0/html and it soft linked to /usr/local/var/www**
index index.html;
}
其他回答
我在Ubuntu上的nginx是“nginx version: nginx/1.9.12 (Ubuntu)” 根路径为/var/www/html/
Ubuntu信息是: 没有LSB模块可用。 分销商ID: Ubuntu 描述:Ubuntu 16.04 LTS 版本:16.04 代号:主客关系的
实际上,如果你只是在Ubuntu上安装了nginx,那么你可以去“/etc/nginx/sites-available”并检查默认文件,有一个类似于“root/ web/root/path/goes/here”的配置。这就是你要找的。
在Mac上使用brew安装nginx:
/ usr / local / etc / nginx / nginx上。
location / {
root html; # **means /usr/local/Cellar/nginx/1.8.0/html and it soft linked to /usr/local/var/www**
index index.html;
}
你可以搜索它,不管他们把它移动到哪里(系统管理移动或更新版本的nginx)
找到/ -name nginx
如果你需要找到编译时定义的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的行,这是定义位置的内容。