민한의 블로그

리눅스 날짜, 위치 설정 및 nginx 설정 본문

인프라/linux

리눅스 날짜, 위치 설정 및 nginx 설정

minhan2 2021. 9. 10. 18:01
728x90
반응형

리눅스를 새로 설치 또는 클라우드 서비스의 리눅스를 첫 이용할때는, 시간과 언어 설정이 되어있을거라는 기대를 하면 안됩니다.
그래도 확인을 위하여

locale
date

명령어를 적어주어 시간과 위치를 파악합니다.

image

sudo apt-get install language-pack-ko

  • 우선 첫번째 할 일은 한글 입력 패키지를 다운받아 설치해야한다. apt-get으로 간단히 설치할 수 있는데, 문제는 어떤 패키지가 있는지 알기 힘들다는것... 구글링 결과 여러가지 썰이 있었는데 아래의 것을 설치하면 된다.
  • $ sudo apt-get install language-pack-ko
  • 다음으로 시스템 전체의 locale을 변경한 후 설정한다.
  • $ sudo locale-gen ko_KR.UTF-8 $ sudo dpkg-reconfigure locales
  • 시간설정도 해주자, 이건 시간설정 asia-seoul
  • sudo dpkg-reconfigure tzdata
  • 그리고 다음번 부팅할 때도 기본적으로 한글을 사용하기 위해 /etc/default/locale 파일을 아래와 같이 변경해준다.
  • LANG="ko_KR.UTF-8"
    LANGUAGE="ko_KR:ko:en_US:en"
  • 이제 다시 접속할 때마다 자동으로 한글을 사용할 수 있다.

단! 이렇게 했음에도 한글이 제대로 표시/입력되지 않을 수 있는데 그건 사용하는 터미널 프로그램의 설정이 잘못되어있기 때문이다. AWS에서 직접 SSH 연결하면 문제가 생기기도한다.

본인의 터미널에서 접속하기로 하자.

다 끝내고 서버 재부팅을 해주어야한다.


지금은 Locale 과 시간설정을 해준것이다.
nginx를 설치하여 간단히 확인해보자.

$ sudo apt-get update
$ sudo apt-get install nginx

다음 명령어를 통해서 버전도 확인하고 설치가 되었는지 확인해봅시다.

$ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)

여기서 sudo apt-get update 안해주고 곧장 install 하면 설치가 안된다.
버전 확인을 하였으면

우리의 서버 IP를 도메인에 검색해보자.

public ip, 공인 아이피로 들어가면 된다. nginx는 기본포트가 80이기에 아이피만 쳐도 들어가집니다.
크롬 등의 웹브라우저에서 기본적으로 80포트는 입력하여도 기본적으로 생략됩니다.
무슨말인가 싶으면, [http://www.naver.com:80][http://www.naver.com:80] 으로 들어가보시면 됩니다.

image

축하합니다! 당신은 웹서버를 배포를 하고있는겁니다.
? 아니 nginx 설치하고 한게없는데 무슨이야기냐고?

cd /etc/nginx
ls -al

nginx를 설치하면, /etc 폴더에 /nginx 폴더가 생성된다.

명령어를 입력하여 nginx 구조를 한번 살펴보자.

image

기본적으로 사용할것은 nginx.conf 파일과 /etc/nginx/sites-available 와 /etc/nginx/site-enabled 폴더이다.
핵심적으로 알아야할것은.
어떤 설정을 해주어야. 외부의 요청에 해당하는 도메인과 포트( 대부분은 http:80, https:443 )에 맞게 내부의 포트로 연결해주냐 이다.
site-available 은 내가 올리기전인 대기중인 설정들이 있는곳이고, site-enabled 에 있는 설정들이 실제로 올라가는 설정들이다.

왜 굳이 그렇게 해야해? 라고 생각된다면, 리버스 프록시를 검색하여 찾아본다.
대표적인 nginx의 기능은 로드밸런싱, 서브 도메인 관리, 캐싱기능 ... 등으로 생각보다 할수있는게 많다.

sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

와 같은 명령어를 입력하여 site-available 에 올린 설정들중에 실제로 작동 시키고싶은것들을 site-enabled 에 소프트 링크를 걸어주는것이다.

소프트 링크란, 윈도우의 바로가기를 생각하면 된다.

sudo ln -s AAA BBB

명령어는
sudo : 관리자 권한으로
ln -s : 바로가기를 만들어줄껀데
AAA를 BBB로 바로가기를 만들어줄꺼야

라는 뜻이다.

image

sudo 로 명령어를 했기때문에 root 사용자의 root 그룹의 소유이고,
이 default 는 /etc/nginx/sites-available/default 의 default를 바로가기로 만든것입니다. 라는 뜻이다.

default파일을 열어보자.

server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
#include snippets/fastcgi-php.conf;
#
## With php-fpm (or other unix sockets):
#fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
## With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
#include snippets/fastcgi-php.conf;
#
## With php-fpm (or other unix sockets):
#fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
## With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
#}

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


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#listen 80;
#listen [::]:80;
#
#server_name example.com;
#
#root /var/www/example.com;
#index index.html;
#
#location / {
#try_files $uri $uri/ =404;
#}
#}

으로 되어있는건 다 주석처리 되어있는것이다.

gzip, https등도 주석처리로 되어있으니, 왠만해서는 필요한것들은 그대로 주석을 풀어주면 된다.

위의 설정중에서

image

server 블록에서
listen 80 -> 80번 포트를 들을것이다(http요청)
root /var/www/html; -> 이곳에서 파일을 제공해줄것이고
index index.html index.htm index.nginx-debian.html; -> index파일은 이녀석들이다.

location / {
 try_files $url $url/ = 404;
}

location 블록은 내가 검색한 url이 루트 경로인지 뒤에 다른 쿼리등이 붙는지 분기를 만들어준다.
루트 경로 이후에 무언가가 붙으면 404를 보여주는 설정이다.


location / {
 (1)
}
location /hello{
 (2)
}

www.miniintern.com 을 검색하면 (1)의 location으로 이동하고
www.miniintern.com/hello 를 검색하면 (2)의 location으로 이동한다.


image)image

이로써 당신이 웹서버를 배포하고있다는것이 증명되었다!

728x90
반응형
Comments