IT

NGinx 기본 공개 www 위치?

lottoking 2020. 3. 26. 08:32
반응형

NGinx 기본 공개 www 위치?


필자는 Apache를 사용해 본 적이 있기 때문에 기본 공개 웹 루트는 일반적으로 /var/www/입니다.

최근에 nginx로 작업하기 시작했지만 기본 공개 웹 루트를 찾지 못하는 것 같습니다.

nginx의 기본 공개 웹 루트는 어디에서 찾을 수 있습니까?


구성에 root /some/absolute/path;명령문이 포함되지 않거나 같은 상대 경로를 사용 하는 명령문이 포함 root some/relative/path;된 경우 결과 경로는 컴파일 시간 옵션에 따라 다릅니다.

소스를 직접 다운로드 하여 컴파일 한 경우 이것이 의미하는 바에 대해 교육적인 추측을 할 수있는 유일한 경우 일 것 입니다. 이 경우 경로 --prefix는 사용 된 것과 관련이 있습니다 . 변경하지 않은 경우 기본값은 /usr/local/nginx입니다. nginx가 via로 컴파일 된 매개 변수를 찾을 수 있으며 첫 번째 매개 변수로 nginx -V나열 --prefix됩니다.

이후 에 지시 기본값 이 물론 초래 귀하의 질문에 대한 대답 인.roothtml/usr/local/nginx/html

그러나 다른 방법으로 nginx를 설치 한 경우 모든 베팅이 해제됩니다. 배포판에서 완전히 다른 기본 경로를 사용할 수 있습니다. 선택의 분포가 사물에 어떤 종류의 디폴트를 사용하는지 알아내는 것은 전적으로 또 다른 과제입니다.


apt-get을 사용하여 Ubuntu에 설치하는 경우을 시도하십시오 /usr/share/nginx/www.

편집하다:

최신 버전에서는 경로가 다음과 같이 변경되었습니다. /usr/share/nginx/html


데비안의 기본 Nginx 디렉토리는 /var/www/nginx-default입니다.

파일을 확인할 수 있습니다 : /etc/nginx/sites-enabled/default

찾아

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

루트는 기본 위치입니다.


'기본 공개 웹 루트'는 nginx -V 출력에서 ​​찾을 수 있습니다.

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

--prefix 값은 질문에 대한 답변입니다. 루트 위의 샘플은 / var / lib / nginx입니다.


Mac OS X에서 brew와 함께 nginx를 설치하면 기본 디렉토리가됩니다.

/usr/local/var/www

그래서:

root html

방법

root /usr/local/var/www/html

html 디렉토리가 없으므로 수동으로 작성해야합니다.


nginx의 루트 폴더를 웹 사이트의 위치에 간단히 매핑 할 수 있습니다 .

nano /etc/nginx/sites-enabled/default

내부 기본 파일의 대한 모습 루트 서버 태그 변경 웹 사이트의 기본 폴더, 예를 들어, 내 웹 사이트 있습니다에서 의 / var / www가

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

        root /var/www; <-- Here!
...

nginx, apache2 및 lighttpd를 평가할 때 모든 것을 / var / www 에있는 내 웹 사이트에 매핑했습니다 . 나는 이것을 효율적으로 평가하는 가장 좋은 방법을 찾았다.

그런 다음 선택한 서버를 시작 / 중지하고 가장 적합한 서버를 확인할 수 있습니다.

예 :

service apache2 stop
service nginx start

Btw, nginx는 실제로 매우 빠릅니다!


여기에 대부분의 사용자가 말했듯 이이 경로 아래에 있습니다.

/usr/share/nginx/html

이것이 기본 경로이지만 그래도 만들 수 있습니다.

필요한 것은 웹 서버 루트 트리에서 하나를 생성하고 "0777"이 아닌 일부 사용자에게만 권한을 부여하는 것입니다. 그러나 경로의 끝 이후 모든 사용자가 경로의 끝을 볼 수 있습니다. 파일과 폴더가 공개적으로 표시됩니다.

예를 들어 다음과 같이 만들 수 있습니다.

home_web/site1/public_html/www/

Nginx에서 가상 호스트를 만들 때마다 자신의 루트 경로를 사용자 정의 할 수 있으며 서버 블록에 다음과 같이 추가하십시오.

 server {
    listen  80;
        server_name  yoursite.com;

root /home_web/site1/public_html/www/;
}

nginx의 기본 웹 폴더는 설치 방법에 따라 다르지만 일반적으로 다음 위치에 있습니다.

/usr/local/nginx/html
/usr/nginx/html

우분투 및 도커 이미지의 경우 :

 /usr/share/nginx/html/

명령을 실행하고을 nginx -V찾으십시오 --prefix. 해당 항목을 사용하여 기본 경로를 찾으십시오.


nginx 설정 파일을 확인하십시오. 이 명령은 시스템에 구성된 모든 항목을 표시합니다.

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

내 컴퓨터에서는 : root / usr / share / nginx / www;


구성을 덤프하십시오.

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

nginx구성 / 설치 방법에 따라 달라지는 점이 다릅니다 .

참고 문헌 :

업데이트 : -T옵션이 언제 추가 되었는지에 대한 혼란이 있습니다 nginx. 이 문서는 2015 년 6 월 16 일 vl-homutov 가 설명서 페이지에 문서화했으며 v1.9.2 릴리스의 일부가 되었습니다 . 릴리스 노트 에도 언급되어 있습니다 . -T옵션은 nginxUbuntu 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

Mac에서 brew와 함께 nginx를 설치하십시오.

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

CentOS, Ubuntu 및 Fedora의 경우 기본 디렉토리는 /usr/share/nginx/html


AWS EC2 Linux의 경우 여기에서 찾을 수 있습니다.

/usr/share/nginx

내 경우에는 /usr/share/nginx/html

당신은 검색을 수행하여 찾을 수 있습니다

find / -name html

Ubuntu 14.04를 사용하는 경우 다음 경로에서 nginx www 디렉토리를 찾을 수 있습니다.

yusuf@yusuf-he:/usr/share/nginx/html$ pwd
/usr/share/nginx/html
yusuf@yusuf-he:/usr/share/nginx/html$

컴파일 타임에 정의 된 nginx 공개 루트 폴더를 찾아야하는 경우 access.log 파일을 확인하면됩니다.

  1. nginx.conf를 엽니
  2. log_format 지시문 찾기
  3. log_format 의 값은 access.log 파일에 정보를 쓰는 데 사용되는 템플릿 문자열입니다 . 이 템플릿 문자열에 $ document_root 변수를 추가 하여 기본 www 루트 위치를 파일에 기록 할 수 있습니다.

다음은 수정 된 log_format 지시문 이있는 nginx.conf 의 http 섹션에있는 예제입니다. $ document_root는 문자열의 시작 부분에 추가됩니다.

    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. 그런 다음 conf.d 디렉토리의 모든 구성 파일 * .conf를 백업 하고 다음 줄을 사용하여 test.conf 구성 파일을 작성하십시오 .

    server{
        listen 80;
        server_name localhost;
    }
    
    1. / etc / hosts 파일에 다음 행을 추가하십시오. 127.0.0.1 localhost

    2. nginx 구성을 다시로드하십시오. nginx -s reload

    3. http : // localhost로 GET 요청 보내기 :curl http://localhost

    4. access.log 의 마지막 문자열을 확인하십시오 .tail -n 1 /var/log/nginx/access.log

다음은이 명령의 샘플 출력입니다. 여기서 / etc / nginx / html 은 컴파일시 정의 된 기본 문서 루트입니다.

    /etc/nginx/html 127.0.0.1 - - [15/Mar/2017:17:12:25 +0200] "GET / HTTP/1.1" 404 169 "-" "curl/7.35.0" "-"

어디로 옮겼 든 상관없이 검색 할 수 있습니다 (시스템 관리자가 이동했거나 최신 버전의 nginx)

찾기 /-이름 nginx


당신은 파일 설정 nginx에 액세스 할 수 있습니다, 당신은 루트 / 경로를 볼 수 있습니다 이 기본값의 nginx 아파치에서/var/www/html


nginx 서버의 기본 인덱스 페이지에도 루트 위치가 표시됩니다. Amazon Linux AMI의 nginx (1.4.3)에서 다음을 얻습니다.

Amazon Linux AMI에서 nginx와 함께 배포되는 기본 index.html 페이지입니다. / usr / share / nginx / html에 있습니다.

이제 콘텐츠를 원하는 위치에 놓고 nginx 구성 파일 /etc/nginx/nginx.conf에서 루트 구성 지시문을 편집해야합니다.


Ubuntu의 내 nginx는 "nginx 버전 : nginx / 1.9.12 (Ubuntu)"이고 루트 경로는 / var / www / html /

우분투 정보는 : 사용 가능한 LSB 모듈이 없습니다. 배급 자 ID : Ubuntu 설명 : Ubuntu 16.04 LTS 릴리스 : 16.04 코드 이름 : xenial

실제로 우분투에 nginx를 설치 한 경우 "/ etc / nginx / sites-available"로 이동하여 기본 파일을 확인할 수 있습니다. "root / web / root / path / goes / here"와 같은 구성이 있습니다. 그리고 그것은 당신이 찾고있는 것입니다.


nginx 및 apache의 기본 디렉토리 인 / var / www /에서 찾을 수 있지만 변경할 수 있습니다. 1 단계는 다음 폴더 / etc / nginx / sites-available로 이동하십시오.

2 단계 기본 파일을 편집하여 위치를 정의하는 루트로 이름이 지정된 행이있는 서버 블록을 찾을 수 있습니다.


우분투 19.04에서 우리는 그것을 발견했습니다.

/ usr / share / nginx / html


nginx / 1.4.6 (우분투)

/etc/nginx$ cat /etc/nginx/sites-available/default | grep -i root
- root /usr/share/nginx/html;

우분투에서 Nginx 기본 루트 디렉토리 위치는 /usr/share/nginx/html


기본값은 nginx가 컴파일 될 때 스크립트 prefix옵션 과 관련이 있습니다 configure. 다음은 데비안의 이상한 샘플입니다.

% 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

그 후, 기본값 root입니다 받는 설정 html디렉토리 (당 등 의 문서 root지침 내에서 될 일이) prefix상기보고에 의해 검증 될 수있는, $document_root간단한 구성 파일에서 변수 :

# 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

그러나 데비안과 같은 악의적 인 배포판은 약간의 즐거움을주기 위해 약간 수정하는 것처럼 보입니다.

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

따라서이 데비안 인스턴스에서 루트가 최종적으로로 설정되어 있음을 알 수 /usr/share/nginx/www있습니다.

그러나 $document_roothttp를 통해 가치를 제공하는 샘플 서버 구성에서 알 수 있듯이 nginx 구성은 간단한 요구 사항 root을 충족 하는 데 필요한 것을 지정하여 한 줄 또는 두 줄의 문제로 자신의 구성을 작성할 수있을 정도로 간단 합니다.


또한 nginx와 함께 WordPress 웹 사이트를 실행하는 Digital Ocean 에서도이 문제가 발생했습니다.

내 해결책은 다음을 수행하는 것이 었습니다.

  1. /etc/nginx/nginx.conf다음을 사용 하여 파일을 수정하십시오 .
server {
root /var/www/html;
}

나는 그때했다 sudo service nginx restart

nginx -V이 명령은 또한 nginx 설정 파일의 위치를 ​​보여줍니다 (광산이 지적되었습니다 /etc/nginx/nginx.conf)


* 기본 페이지 웹은 var / www / html에 할당 * 기본 구성 서버 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;
    }
}

* 기본 설정 서버 etc / nginx / nginx.conf

함유량..

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

ip 클라이언트가있는 기본 액세스 로그 var / log / nginx / ...


Alpine Linux에는 기본 위치가 전혀 없습니다. 파일 /etc/nginx/conf.d/default.conf은 말합니다 :

# Everything is a 404
location / {
    return 404;
}

# You may need this to prevent return 404 recursion.
location = /404.html {
    internal;
}

root /var/www/localhost/htdocs원하는 디렉토리를 가리키는 줄로 바꾸십시오. 그런 다음 sudo service nginx restart다시 시작하십시오.

참고 URL : https://stackoverflow.com/questions/10674867/nginx-default-public-www-location

반응형