我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
在我的例子中,它在/usr/share/nginx/html中
您可以尝试通过执行搜索来查找
find / -name html
其他回答
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;
}
根节点是默认位置。
在我的例子中,它在/usr/share/nginx/html中
您可以尝试通过执行搜索来查找
find / -name html
默认值与nginx编译时configure脚本的prefix选项有关;下面是一些来自Debian的奇怪的例子:
% nginx -V | & tr ' ' "\n" | fgrep -e path -e prefix
--prefix=/etc/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-log-path=/var/log/nginx/access.log
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi
--lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid
随后,root的默认值被设置为html目录(根据root指令的文档),它恰好在prefix中,可以通过查看简单配置文件中的$document_root变量来验证:
# printf 'server{listen 4867;return 200 $document_root\\n;}\n' \
>/etc/nginx/conf.d/so.10674867.conf
# nginx -s reload && curl localhost:4867
/etc/nginx/html
然而,像Debian这样的邪恶发行版似乎对它进行了相当大的修改,以让你获得额外的娱乐:
% fgrep -e root -e include /etc/nginx/nginx.conf
include /etc/nginx/mime.types;
#include /etc/nginx/naxsi_core.rules;
#passenger_root /usr;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
% fgrep -e root -e include \
/etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/*
/etc/nginx/conf.d/so.10674867.conf:server{listen 4867;return 200 $document_root\n;}
/etc/nginx/sites-enabled/default: root /usr/share/nginx/www;
/etc/nginx/sites-enabled/default: # include /etc/nginx/naxsi.rules
/etc/nginx/sites-enabled/default: # root /usr/share/nginx/www;
/etc/nginx/sites-enabled/default: # include fastcgi_params;
/etc/nginx/sites-enabled/default: # deny access to .htaccess files, if Apache's document root
/etc/nginx/sites-enabled/default:# root html;
/etc/nginx/sites-enabled/default:# root html;
所以,在这个Debian实例中,你可以看到根目录最终被设置为/usr/share/nginx/www.
但是,正如您在示例服务器配置中看到的,它将通过http提供$document_root值,配置nginx非常简单,您可以在一两行代码内编写自己的配置,指定所需的根以满足您的确切需求。
你可以简单地将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是“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”的配置。这就是你要找的。