我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
你可以简单地将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实际上非常快!
其他回答
如果你需要找到编译时定义的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" "-"
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;
}
根节点是默认位置。
对于AWS EC2 Linux,您将在这里找到:
/usr/share/nginx
转储配置:
$ 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
你可以访问nginx文件配置,你可以看到root /path。在这个 nginx apache的默认地址是/var/www/html