Reputation:
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?
Upvotes: 411
Views: 1063091
Reputation: 21
The default public location for serving files in Nginx is typically set to /var/www/html or /usr/share/nginx/html.
Upvotes: 1
Reputation: 254
In case if you have installed in via homebrew and you are using macOS , you can find it at /opt/homebrew/Cellar/nginx/1.23.2/html
, replace 1.23.2 with your version .
Upvotes: 0
Reputation: 1089
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.
Upvotes: 1
Reputation: 11957
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;
Upvotes: 17
Reputation: 5639
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.
Upvotes: 563
Reputation: 79
*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/...
Upvotes: 7
Reputation: 3970
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.
Upvotes: 1
Reputation: 21
I also had this issue on Digital Ocean running a WordPress website with nginx.
My solution was to do the following:
/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
)
Upvotes: 2
Reputation: 303
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.
Upvotes: 3
Reputation: 57
you can access file config nginx,you can see root /path. in this
default of nginx apache at /var/www/html
Upvotes: 4
Reputation: 361
In Ubuntu,
Nginx default root Directory location is /usr/share/nginx/html
Upvotes: 3
Reputation: 1010
You can search for it, no matter where did they move it (system admin moved or newer version of nginx)
find / -name nginx
Upvotes: 5
Reputation: 1072
For CentOS, Ubuntu and Fedora, the default directory is /usr/share/nginx/html
Upvotes: 9
Reputation: 27238
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.
Upvotes: 1
Reputation: 3236
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 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
, 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.
Upvotes: 201
Reputation: 111
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;
}
Upvotes: 11
Reputation: 91
If you need to find out nginx public root folder that was defined at compile time you can just check your access.log 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. .......
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;
}
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" "-"
Upvotes: 4
Reputation: 1619
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$
Upvotes: 5
Reputation: 5320
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
Upvotes: 12
Reputation: 35984
For nginx/1.4.6 (Ubuntu)
/etc/nginx$ cat /etc/nginx/sites-available/default | grep -i root
- root /usr/share/nginx/html;
Upvotes: 2
Reputation: 1407
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.
Upvotes: 88
Reputation: 61
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.
Upvotes: 3
Reputation: 827
'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
Upvotes: 56
Reputation: 111
Run the command nginx -V
and look for the --prefix
. Use that entry to locate your default paths.
Upvotes: 11
Reputation: 813
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.
Upvotes: 27
Reputation: 13910
In my case it was in /usr/share/nginx/html
you can try to find by performing a search
find / -name html
Upvotes: 7
Reputation: 4447
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/;
}
Upvotes: 23