NGinx domyślna publiczna lokalizacja www?

Pracowałem już z Apache ' em, więc wiem, że domyślnym publicznym korzeniem sieci jest typowo /var/www/.

Ostatnio zacząłem pracować z nginx, ale nie mogę znaleźć domyślnego publicznego katalogu głównego.

Gdzie mogę znaleźć domyślny publiczny korzeń internetowy dla nginx?

 237
Author: user456584, 2012-05-20

26 answers

Jeśli Twoja konfiguracja nie zawiera instrukcji root /some/absolute/path; lub zawiera taką, która używa względnej ścieżki jak root some/relative/path;, to ścieżka wynikowa zależy od opcji kompilacji.

Prawdopodobnie jedynym przypadkiem, który pozwoliłby ci zgadnąć, co to oznacza dla ciebie, byłby, gdybyś pobrał i skompilował źródło samodzielnie. W takim przypadku ścieżki byłyby względne do tego, co zostało użyte --prefix. Jeśli go nie zmieniłeś, domyślnie jest to /usr/local/nginx. Można znaleźć parametry nginx został skompilowany z via nginx -V, wymienia --prefix jako pierwszy.

Ponieważ dyrektywa root domyślnie html, to oczywiście sprawi, że /usr/local/nginx/html będzie odpowiedzią na twoje pytanie.

Jeśli jednak zainstalujesz nginx w jakikolwiek inny sposób, wszystkie zakłady są wykluczone. Twoja dystrybucja może używać zupełnie innych ścieżek domyślnych. Nauka, aby dowiedzieć się, jakiego rodzaju domyślnych dystrybucji używa do rzeczy jest zupełnie innym zadaniem.
 121
Author: Gnarfoz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-10 09:08:19

Jeśli instalujesz na Ubuntu używając apt-get, spróbuj /usr/share/nginx/www.

EDIT:

W nowszych wersjach ścieżka została zmieniona na: /usr/share/nginx/html

 384
Author: Lufix,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-11 18:38:19

W Debianie jest to jeden z najbardziej popularnych katalogów Nginx.

Możesz sprawdzić plik: /etc/nginx/sites-enabled/default

I znaleźć

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;
        }

Root jest domyślną lokalizacją.

 49
Author: Babistalikesflyingonrails,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-19 12:42:53

Nginx-V - 1000-1000-1000-1000-1000-1000-1000-1000-1000]}

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

Wartość --prefix jest odpowiedzią na pytanie. dla przykładu powyżej katalogu głównego jest / var / lib / nginx

 27
Author: Serge S,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-05 17:06:49

W systemie Mac OS X zainstalowanie nginx z brew powoduje utworzenie domyślnego katalogu:

/usr/local/var/www

Więc:

root html

Oznacza

root /usr/local/var/www/html

Nie ma katalogu html, więc musiałby być utworzony ręcznie.

 22
Author: freegnu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-09 22:45:54

Możesz po prostu zmapować katalog główny nginx do lokalizacji Twojej witryny:

nano /etc/nginx/sites-enabled/default

W pliku default poszukaj root w tagu server i zmień domyślny folder swojej witryny, np. moje witryny znajdują się w / var / www

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www; <-- Here!
...
W związku z tym, że nie jesteśmy w stanie sprostać wymaganiom naszych klientów, nie jesteśmy w stanie sprostać wymaganiom naszych klientów. Uznałem to za najlepszy sposób na skuteczną ocenę.

Następnie możesz uruchomić / zatrzymać serwer do wyboru i zobacz, który działa najlepiej.

Np.

service apache2 stop
service nginx start
[[3]}Btw, nginx faktycznie jest bardzo szybki!
 16
Author: Waqas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-01 11:24:37

Jak większość użytkowników tutaj powiedziała, jest pod tą ścieżką:

/usr/share/nginx/html

Jest to domyślna ścieżka, ale możesz zrobić swoją.

Wszystko, czego potrzebujesz, to utworzyć je w drzewie głównym serwera sieci Web i nadać mu pewne uprawnienia "nie 0777" i tylko dla jednego użytkownika i widoczne tylko dla tego użytkownika, ale koniec ścieżki jest widoczny dla wszystkich, ponieważ koniec ścieżki jest to, co Twoje pliki i foldery będą wyświetlane przez publiczne.

Na przykład, można zrobić taki jak to:

home_web/site1/public_html/www/
W Nginx możesz skonfigurować własną ścieżkę root ' a, po prostu dodaj coś takiego w swoim bloku serwerowym:]}
 server {
    listen  80;
        server_name  yoursite.com;

root /home_web/site1/public_html/www/;
}
 15
Author: Digital site,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-05 14:08:34

Jeśli chcesz dowiedzieć się więcej o nginx, skontaktuj się z nami, aby uzyskać więcej informacji]}

/usr/local/nginx/html
/usr/nginx/html
 11
Author: Ja͢ck,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-05-20 16:05:25

Uruchom polecenie nginx -V i poszukaj --prefix. Użyj tej pozycji, aby zlokalizować domyślne ścieżki.

 9
Author: Jack,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-04-07 16:17:47

Na Macu zainstaluj nginx z 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;
}  
 8
Author: user2413075,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-09 13:03:51

Zrzuć konfigurację:

$ nginx -T
...
server {
    ...
    location / {
        root   /usr/share/nginx/html;
        ...
    }
    ...
}

To, co otrzymujesz, może być inne, ponieważ zależy to od tego, jak twoja nginx została skonfigurowana/zainstalowana.

Bibliografia:

Aktualizacja: jest pewne zamieszanie w kwestii, czy / kiedy Opcja -T została dodana do nginx. Zostało to udokumentowane na stronie podręcznika przez vl-homutov w czerwcu 2015 roku 16, która stała się częścią wydania v1.9.2 . Jest nawet wspomniane w uwagach do wydania. Opcja -T jest obecna w każdym wydaniu nginx od tego czasu, w tym w wersji dostępnej na 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
 7
Author: rubicks,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-22 14:58:13

Dla CentOS, Ubuntu i Fedory domyślnym katalogiem jest /usr/share/nginx/html

 7
Author: MucaP,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-15 14:53:05

W moim przypadku było to w /usr/share/nginx/html

Możesz spróbować znaleźć wykonując wyszukiwanie

find / -name html
 5
Author: Eduardo Dennis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-04 01:44:37

Jeśli korzystasz z Ubuntu 14.04, możesz znaleźć Katalog www nginx w następującej ścieżce:

yusuf@yusuf-he:/usr/share/nginx/html$ pwd
/usr/share/nginx/html
yusuf@yusuf-he:/usr/share/nginx/html$
 5
Author: Yusuf Ibrahim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-01-01 12:44:37

Dla obrazów Ubuntu i Dockera:

 /usr/share/nginx/html/
 5
Author: DimiDak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-21 22:56:28

Aby zauważyć, że domyślna strona indeksu dla serwera nginx będzie również wyświetlać lokalizację roota. Z nginx (1.4.3) na Amazon Linux AMI, dostajesz następujące:

Jest to domyślny indeks.strona html, która jest dystrybuowana z nginx na Amazon Linux AMI. W tym celu prosimy o kontakt z działem obsługi klienta.

W tym celu należy umieścić zawartość w wybranym przez siebie miejscu i edytować dyrektywę konfiguracyjną root w pliku konfiguracyjnym nginx /etc/nginx/nginx.conf
 3
Author: jboles,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-05 12:01:58

Zażądaj informacji za pomocą tego polecenia:

cat /etc/nginx/sites-enabled/default |grep "root"

Otrzymałem: root /usr/share/nginx/www;

 3
Author: Thamme Gowda,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-01-02 10:53:52

Jeśli chcesz znaleźć publiczny katalog główny nginx, który został zdefiniowany podczas kompilacji, możesz po prostu sprawdzić swój dostęp.plik dziennika.

  1. Otwórz nginx.conf
  2. Znajdź dyrektywę log_format
  3. wartość log_format jest ciągiem szablonów, który służy do zapisu informacji do dostępu .log plik. Możesz dodać zmienną $document_root do tego łańcucha szablonu, aby zalogować domyślną lokalizację głównego katalogu www do pliku.
W tym celu należy skontaktować się z naszym biurem obsługi klienta.conf ze zmodyfikowaną dyrektywą log_format, $document_root jest dodawany na początku łańcucha znaków:
    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. Następnie wykonaj kopię zapasową wszystkich plików konfiguracyjnych*.conf in conf.katalog d i utwórz tam plik konfiguracyjny test.conf z następującymi liniami:

    server{
        listen 80;
        server_name localhost;
    }
    
    1. Dodaj następujący wiersz do pliku/etc / hosts: 127.0.0.1 localhost

    2. Przeładuj konfigurację nginx: nginx -s reload

    3. Wyślij zapytanie GET do http://localhost: curl http://localhost

    4. Sprawdź ostatni łańcuch dostępu .log:tail -n 1 /var/log/nginx/access.log

Oto Przykładowe wyjście tego polecenia, gdzie / etc / nginx / html jest domyślnym rootem dokumentu zdefiniowanym podczas kompilacji:

    /etc/nginx/html 127.0.0.1 - - [15/Mar/2017:17:12:25 +0200] "GET / HTTP/1.1" 404 169 "-" "curl/7.35.0" "-"
 3
Author: G.Denis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-15 16:18:15

Możesz uzyskać dostęp do pliku config nginx, możesz zobaczyć root / path. w tym w tym celu prosimy o zapoznanie się z naszą Polityką Prywatności.]}

 3
Author: tomnyson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-21 22:56:58

Mój nginx na Ubuntu to " wersja nginx: nginx / 1.9.12 (Ubuntu)" a ścieżka główna to / var / www / html /

Ubuntu info jest : Brak modułów LSB. ID dystrybutora: Ubuntu Opis: Ubuntu 16.04 LTS Premiera: 16.04 Nazwa kodowa: xenial

Właściwie, jeśli właśnie zainstalowałeś nginx na Ubuntu, możesz przejść do "/ etc /nginx/sites-available" i sprawdzić domyślny plik, istnieje konfiguracja taka jak "root/web/root/path / goes / here". I tego właśnie szukasz.

 2
Author: Daniel Dong,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-10-19 09:00:14

Dla AWS EC2 Linux znajdziesz tutaj:

/usr/share/nginx
 2
Author: Vivek Sharma,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-21 22:57:07

Dla nginx/1.4.6 (Ubuntu)

/etc/nginx$ cat /etc/nginx/sites-available/default | grep -i root
- root /usr/share/nginx/html;
 1
Author: lfender6445,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-12-22 02:19:24

W tym przypadku, gdy nginx jest kompilowany, domyślna wartość jest powiązana z opcją prefix skryptu configure; Oto dziwna próbka z Debiana:

% 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

Następnie wartość domyślna root jest ustawiony na html katalog (zgodnie z dokumentacją dyrektywy root ), która znajduje się w prefix, co można sprawdzić patrząc na $document_root zmienna z prostego pliku konfiguracyjnego:

# 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

Jednak złe dystrybucje jak Wydaje się, że Debian trochę go zmodyfikował, aby zapewnić Ci dodatkową rozrywkę:

% 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;

Tak więc, na tej instancji Debiana, możesz zobaczyć, że root został ostatecznie ustawiony na /usr/share/nginx/www.

Dzięki temu, że nginx jest w stanie skonfigurować swoją własną konfigurację w jednym lub dwóch wierszach, możesz określić wymagane root, aby spełnić twoje potrzeby.
 1
Author: cnst,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-08-27 21:08:08

Możesz go wyszukać, bez względu na to, gdzie go przenieśli (administrator systemu przeniósł się lub nowsza wersja nginx)

Znajdź / - nazwa nginx

 1
Author: Dylan B,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-15 04:48:35

Jeśli chcesz dowiedzieć się więcej na ten temat, skontaktuj się z nami, aby uzyskać więcej informacji na ten temat. Krok 1 Przejdź do folderu / etc / nginx / sites-available

Krok 2 edytuj domyślny plik, w którym możesz znaleźć blok serwera, pod którym będzie linia o nazwie root, która określa lokalizację.

 1
Author: gokul kandasamy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-06 09:14:03

W Ubuntu, Nginx domyślnie znajduje się w katalogu głównym /usr/share/nginx/html

 0
Author: Syed Abdul Qadeer,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-06-21 22:56:41