NGinx Default public www location?

前端 未结 30 906
野性不改
野性不改 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 18:09

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

    If you need to find out nginx public root folder that was defined at compile time you can just check your access.log file.

    1. Open nginx.conf
    2. Find the log_format directive
    3. 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. .......
    
    1. 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;
      }
      
      1. Add following line to /etc/hosts file: 127.0.0.1 localhost

      2. Reload nginx configuration: nginx -s reload

      3. Send GET request to http://localhost: curl http://localhost

      4. 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" "-"
    
    0 讨论(0)
  • 2020-11-28 18:11

    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.

    0 讨论(0)
  • 2020-11-28 18:12

    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$
    
    0 讨论(0)
  • 2020-11-28 18:13

    For nginx/1.4.6 (Ubuntu)

    /etc/nginx$ cat /etc/nginx/sites-available/default | grep -i root
    - root /usr/share/nginx/html;
    
    0 讨论(0)
  • 2020-11-28 18:14

    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.

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