我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
我以前使用过Apache,所以我知道默认的公共web根目录通常是/var/www/。
我最近开始使用nginx,但我似乎找不到默认的公共web根。
我在哪里可以找到nginx的默认公共web根?
当前回答
默认值与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非常简单,您可以在一两行代码内编写自己的配置,指定所需的根以满足您的确切需求。
其他回答
Alpine Linux根本没有任何默认位置。文件/etc/nginx/conf.d/default.conf说:
# Everything is a 404
location / {
return 404;
}
# You may need this to prevent return 404 recursion.
location = /404.html {
internal;
}
替换成像root /var/www/localhost/htdocs这样的一行来指向你想要的目录。然后sudo service nginx restart重新启动。
对于AWS EC2 Linux,您将在这里找到:
/usr/share/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实际上非常快!
导航到文件 $ cat /etc/nginx/nginx.conf
在HTTP——>服务器——>根下的文件中
在这里,您将看到根目录的默认位置和所有错误页面。
你可以搜索它,不管他们把它移动到哪里(系统管理移动或更新版本的nginx)
找到/ -name nginx