본문 바로가기

구름 IDE - 웹페이지 만들기

클라우드 구름 IDE 웹페이지 만들기(#3) - nginx의 HTML 폴더 경로 변경

1. 개요

우리가 html 문서를 직접 작성하여 웹 사이트를 구축해보기 위해서 html 문서들이 존재하는 폴더의 위치를 설정해주겠습니다.


2. nginx의 HTML 폴더 경로 변경

cd /etc/eginx 이라는 명령어를 입력하여 해당 폴더로 입력 후 ls 라는 명령어를 입력해줍니다. 우리가 이동한 폴더에는 각종 nginx 관련 환경설정 파일들이 존재하는 것을 볼 수 있습니다.

cd sites-enabled 라는 명령어를 입력하여 해당 폴더로 이동한 후에 ls 명령어를 입력하면 default 문서가 있는 것을 확인할 수 있습니다. 이제 이 문서를 수정하여 html 문서가 존재하는 기본적인 폴더의 경로를 바꿔주도록 하겠습니다.

default 문서에는 웹 서버에 접근 관련 설정을 할 수 있기 때문에 이 파일을 수정해주도록 하겠습니다. cat default 라는 명령어를 입력하여 default 문서에 담긴 다양한 환경설정 코드를 볼 수 있습니다.

 

 

You may add here your
# server {
#       ...
# }
# statements for each of your virtual hosts to this file

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

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

        root /usr/share/nginx/html;
        // 이 부분을 수정하세요.
        
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #       proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #       root /usr/share/nginx/html;
        #}
        
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
        #       fastcgi_index index.php;
        #       include fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#       listen 8000;
#       listen somename:8080;
#       server_name somename alias another.alias;
#       root html;
#       index index.html index.htm;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

# HTTPS server
#
#server {
#       listen 443;
#       server_name localhost;
#
#       root html;
#       index index.html index.htm;
#
#       ssl on;
#       ssl_certificate cert.pem;
#       ssl_certificate_key cert.key;
#
#       ssl_session_timeout 5m;
#
#       ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
#       ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
#       ssl_prefer_server_ciphers on;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

 

cat 명령어를 통해서 default의 내용을 알아보았으니, vi default 명령어를 통해서 수정을 해주겠습니다. vi default 명령어를 입력 후 엔터를 친 다음 A를 눌러주면 --끼워넣기-- 가 생기는 것을 볼 수 있습니다.

코드를 잘 찾아보면 root /usr/share/nginx/html; 을 찾을 수가 있는데, 이 부분을 root /workspace/PASCUCU; 로 바꿔주면 됩니다. 그러면 이 PASCUCU 폴더 안쪽에 있는 파일들이 html 문서로써 브라우저서 접속할 수 있게 됩니다. 수정을 완료했으면 Esc 버튼을 누른 후 :wq! 를 입력하여 저장을 하고 빠져나옵니다.

빠져나온 후에 service nginx stop 명령어를 사용하여 웹 서버를 중지시켜줍니다. 이어서 cd /workspace/PASCUCU 명령어를 입력하여 해당 폴더로 이동해줍니다. 그리고 vi index.html 명령어를 입력한 후에 A를 눌러서 Hello를 입력하도록 합니다. Hello를 입력한 후에는 Esc 버튼을 누른 후 :wq! 를 입력하여 저장하고 빠져나오면 왼쪽 파일 목록에 index.html이 생성된 것을 볼 수 있습니다.