NGinx Default public www location?

前端 未结 30 940
野性不改
野性不改 2020-11-28 17:51

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 ca

相关标签:
30条回答
  • 2020-11-28 17:51

    '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

    0 讨论(0)
  • 2020-11-28 17:51

    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:

    • -T option on the man page

    • -T option in the help message

    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
    
    0 讨论(0)
  • 2020-11-28 17:51

    In Ubuntu, Nginx default root Directory location is /usr/share/nginx/html

    0 讨论(0)
  • 2020-11-28 17:51

    I also had this issue on Digital Ocean running a WordPress website with nginx.

    My solution was to do the following:

    1. 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)

    0 讨论(0)
  • 2020-11-28 17:52

    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/;
    }
    
    0 讨论(0)
  • 2020-11-28 17:52

    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.

    0 讨论(0)
提交回复
热议问题