我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
如果你需要找到编译时定义的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服务器的默认索引页面也会显示根位置。从Amazon Linux AMI上的nginx(1.4.3),您可以得到以下内容:
这是默认的index.html页面,在Amazon Linux AMI上与nginx一起分发。它位于/usr/share/nginx/html。
你现在应该把你的内容放在你选择的位置,并编辑nginx配置文件/etc/nginx/nginx.conf中的根配置指令
导航到文件 $ cat /etc/nginx/nginx.conf
在HTTP——>服务器——>根下的文件中
在这里,您将看到根目录的默认位置和所有错误页面。
在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配置文件来确定。 这个命令是greps在你的机器上配置的任何东西:
cat /etc/nginx/sites-enabled/default |grep "root"
在我的机器上,它是:root /usr/share/nginx/www;
如果你是通过homebrew安装的,并且你使用的是macOS,你可以在/opt/homebrew/Cellar/nginx/1.23.2/html找到它,用你的版本替换1.23.2。