NGinx Default public www location?
NginxNginx Problem Overview
I have worked with Apache before, so I am aware that the default public web root is typically /var/www/
.
I recently started working with nginx, but I can't seem to find the default public web root.
Where can I find the default public web root for nginx?
Nginx Solutions
Solution 1 - Nginx
If installing on Ubuntu using apt-get, try /usr/share/nginx/www
.
EDIT:
On more recent versions the path has changed to:
/usr/share/nginx/html
2019 EDIT:
Might try in /var/www/html/index.nginx-debian.html
too.
Solution 2 - Nginx
If your configuration does not include a root /some/absolute/path;
statement, or it includes one that uses a relative path like root some/relative/path;
, then the resulting path depends on compile-time options.
Probably the only case that would allow you to make an educated guess as to what this means for you would be, if you [downloaded][1] and compiled the source yourself. In that case, the paths would be relative to whatever --prefix
was used. If you didn't change it, it defaults to /usr/local/nginx
. You can find the parameters nginx was compiled with via nginx -V
, it lists --prefix
as the first one.
Since [the root
directive defaults to html
][2], this would, of course, result in /usr/local/nginx/html
being the answer to your question.
However, if you installed nginx in any other way, all bets are off. Your distribution might use entirely different default paths. Learning to figure out what kind of defaults your distribution of choice uses for things is another task entirely.
[1]: http://nginx.org/en/download.html] "www.nginx.org" [2]: http://nginx.org/en/docs/http/ngx_http_core_module.html#root "nginx documentation"
Solution 3 - Nginx
The default Nginx directory on Debian is /var/www/nginx-default
.
You can check the file: /etc/nginx/sites-enabled/default
and find
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;
}
The root is the default location.
Solution 4 - Nginx
'default public web root' can be found from nginx -V output:
nginx -V
nginx version: nginx/1.10.1
built with OpenSSL 1.0.2h 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/run/nginx/nginx.pid --lock-path=/run/nginx/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --user=nginx --group=nginx --with-ipv6 --with-file-aio --with-pcre-jit --with-http_dav_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module --with-http_auth_request_module --with-mail --with-mail_ssl_module
the --prefix value is the answer to the question. for the sample above the root is /var/lib/nginx
Solution 5 - Nginx
For Ubuntu and docker images:
/usr/share/nginx/html/
Solution 6 - Nginx
On Mac OS X installing nginx with brew makes the default directory:
/usr/local/var/www
So:
root html
means
root /usr/local/var/www/html
There is no html directory so it would have to be created manually.
Solution 7 - Nginx
as most users here said, it is under this path:
/usr/share/nginx/html
This is the default path, but you can make yours though.
all you need is to create one in the web server root tree and give it some permissions "not 0777" and only for one user and visible to that user only, but the end of the path is visible to everyone since the end of the path is what your files and folders will be viewed by public.
for example, you can make one like this:
home_web/site1/public_html/www/
whenever you make a virtual host in Nginx you can customize your own root path, just add something like this in your server block:
server {
listen 80;
server_name yoursite.com;
root /home_web/site1/public_html/www/;
}
Solution 8 - Nginx
You can simply map nginx's root folder to the location of your website:
nano /etc/nginx/sites-enabled/default
inside the default file, look for the root in the server tag and change your website's default folder, e.g. my websites are at /var/www
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www; <-- Here!
...
When I was evaluating nginx, apache2 and lighttpd, I mapped all of them to my website sitting at /var/www. I found this the best way to evaluate efficiently.
Then you can start/stop the server of your choice and see which performs best.
e.g.
service apache2 stop
service nginx start
Btw, nginx actually is very fast!
Solution 9 - Nginx
Look into nginx config file to be sure. This command greps for whatever is configured on your Machine:
cat /etc/nginx/sites-enabled/default |grep "root"
on my machine it was :root /usr/share/nginx/www;
Solution 10 - Nginx
The default web folder for nginx depends on how you installed it, but normally it's in these locations:
/usr/local/nginx/html
/usr/nginx/html
Solution 11 - Nginx
Dump the configuration:
$ nginx -T
...
server {
...
location / {
root /usr/share/nginx/html;
...
}
...
}
What you get might be different since it depends on how your nginx
was configured/installed.
References:
Update: There's some confusion on the issue of if/when the -T
option was added to nginx
. It was documented in the man page by vl-homutov on 2015 June 16, which became part of the v1.9.2 release. It's even mentioned in the release notes. The -T
option has been present in every nginx
release since, including the one available on 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
Solution 12 - Nginx
Run the command nginx -V
and look for the --prefix
. Use that entry to locate your default paths.
Solution 13 - Nginx
On Mac install nginx with brew:
/usr/local/etc/nginx/nginx.conf
location / {
root html; # **means /usr/local/Cellar/nginx/1.8.0/html and it soft linked to /usr/local/var/www**
index index.html;
}
Solution 14 - Nginx
For CentOS, Ubuntu and Fedora, the default directory is /usr/share/nginx/html
Solution 15 - Nginx
For AWS EC2 Linux you will find here:
/usr/share/nginx
Solution 16 - Nginx
Just to note that the default index page for the nginx server will also display the root location as well. From the nginx (1.4.3) on Amazon Linux AMI, you get the following:
This is the default index.html page that is distributed with nginx on the Amazon Linux AMI. It is located in /usr/share/nginx/html.
You should now put your content in a location of your choice and edit the root configuration directive in the nginx configuration file /etc/nginx/nginx.conf
Solution 17 - Nginx
In my case it was in /usr/share/nginx/html
you can try to find by performing a search
find / -name html
Solution 18 - Nginx
If you are on Ubuntu 14.04 you can find nginx www directory at following path:
yusuf@yusuf-he:/usr/share/nginx/html$ pwd
/usr/share/nginx/html
yusuf@yusuf-he:/usr/share/nginx/html$
Solution 19 - Nginx
You can search for it, no matter where did they move it (system admin moved or newer version of nginx)
> find / -name nginx
Solution 20 - Nginx
you can access file config nginx,you can see root /path. in this
default of nginx apache at /var/www/html
Solution 21 - Nginx
If you need to find out nginx public root folder that was defined at compile time you can just check your access.log file.
- Open nginx.conf
- Find the log_format directive
- The value of the log_format is a template string that is used to write information to the access.log file. You can add $document_root variable to this template string to log default www root location to a file.
Here is an example from the http section of nginx.conf with modified log_format directive, $document_root is added at the beginning of the string:
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. .......
4. Then backup all configuration files *.conf in conf.d directory and create there configuration file, test.conf with the following lines:
server{
listen 80;
server_name localhost;
}
5. Add following line to /etc/hosts file: 127.0.0.1 localhost
-
Reload nginx configuration:
nginx -s reload
-
Send GET request to http://localhost:
curl http://localhost
-
Check the last string of access.log:
tail -n 1 /var/log/nginx/access.log
Here is the sample output of this command, where /etc/nginx/html is the default document root defined at compile time :
/etc/nginx/html 127.0.0.1 - - [15/Mar/2017:17:12:25 +0200] "GET / HTTP/1.1" 404 169 "-" "curl/7.35.0" "-"
Solution 22 - Nginx
*default pages web allocated in var/www/html *default configuration server etc/nginx/sites/avaliable/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.php;
server_name _;
location /data/ {
autoindex on;
}
location /Maxtor {
root /media/odroid/;
autoindex on;
}
# This option is important for using PHP.
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
}
}
*default configuracion server etc/nginx/nginx.conf
content..
user www-data;
worker_processes 8;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
default access logs with ip clients var/log/nginx/...
Solution 23 - Nginx
My nginx on Ubuntu is "nginx version: nginx/1.9.12 (Ubuntu)" and root path is /var/www/html/
Ubuntu info is : No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Release: 16.04 Codename: xenial
Actually, if you just installed nginx on Ubuntu, then you can go to "/etc/nginx/sites-available" and check the default file, there is a configuration like "root /web/root/path/goes/here". And that is what you are looking for.
Solution 24 - Nginx
In Ubuntu,
Nginx default root Directory location is /usr/share/nginx/html
Solution 25 - Nginx
You can find it in /var/www/ that is default directory for nginx and apache but you can change it. step 1 go to the following folder /etc/nginx/sites-available
step 2 edit default file in that you can find a server block under that there will be line named as root that is what defines the location.
Solution 26 - Nginx
in ubuntu 19.04, we found it on
> /usr/share/nginx/html
Solution 27 - Nginx
For nginx/1.4.6 (Ubuntu)
/etc/nginx$ cat /etc/nginx/sites-available/default | grep -i root
- root /usr/share/nginx/html;
Solution 28 - Nginx
I also had this issue on Digital Ocean running a WordPress website with nginx.
My solution was to do the following:
- Modify the
/etc/nginx/nginx.conf
file with the following:
server {
root /var/www/html;
}
I then had to sudo service nginx restart
nginx -V
command also shows you where your nginx config file is located as well (mine was pointed at /etc/nginx/nginx.conf
)
Solution 29 - Nginx
The default is related to the prefix
option of the configure
script when nginx is compiled; here's some strange sample from 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
Subsequently, the default value of root
is set to the html
directory (as per the documentation of the root
directive), which happens to be within prefix
, as can be verified by looking at the $document_root
variable from a simple configuration file:
# 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
However, evil distributions like Debian seem to modify it quite a bit, to keep you extra entertained:
% 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;
So, on this instance of Debian, you can see that the root is finally set to /usr/share/nginx/www
.
But as you saw with the sample server configuration that would serve its $document_root
value over http, configuring nginx is simple enough that you can write your own configuration in a matter of a single line or two, specifying the required root
to meet your exact needs.
Solution 30 - Nginx
Alpine Linux does not have any default location at all. The file /etc/nginx/conf.d/default.conf
says:
# Everything is a 404
location / {
return 404;
}
# You may need this to prevent return 404 recursion.
location = /404.html {
internal;
}
Replace those with a line like root /var/www/localhost/htdocs
to point to the directory you want. Then sudo service nginx restart
to restart.
Solution 31 - Nginx
navigate to file $ cat /etc/nginx/nginx.conf
inside the file under section http --> server --> root
here you will see the default location for root directory and all the error page.