/
์—”์ง„์—‘์Šค ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์„ค์ •(nginx Virtual Host Setup)

์—”์ง„์—‘์Šค ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์„ค์ •(nginx Virtual Host Setup)


Ubuntu ๋ฐฉ์‹์˜ ์žฅ์ 

๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ๋Š” ์›น ์„œ๋ฒ„์—์„œ ๊ฐ€์žฅ ๋งŽ์ด ์„ค์ •ํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋ฉฐ ์šฐ๋ถ„ํˆฌ์˜ ๊ฒฝ์šฐ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์„ค์ • ํŒŒ์ผ์€ sites-available ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์œ„์น˜์‹œํ‚ค๊ณ  ์‹ค์ œ ๋™์ž‘์‹œํ‚ฌ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ sites-enabled/ ์— symbolic link ๋ฅผ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.


์ฆ‰ lesstif.com ์ด๋ผ๋Š” ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ /etc/nginx/sites-available/lesstif.com ํŒŒ์ผ์— ์„ค์ •ํ•˜๊ณ  ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ์—๋Š” ๋‹ค์Œ ๋ช…๋ น์–ด๋กœ symbolic link๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ln -s /etc/nginx/sites-available/lesstif.com /etc/nginx/sites-enabled


๋ฌผ๋ก  ์›น ์„œ๋ฒ„๊ฐ€ ์ œ๋Œ€๋กœ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์„ค์ •์„ ์ฝ๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‚ด์šฉ์„ ๋ฉ”์ธ ์„ค์ • ํŒŒ์ผ์ธ /etc/nginx/nginx.conf ์— ๋„ฃ์–ด ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

include /etc/nginx/sites-enabled/*;



๋งŒ์•ฝ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ๋ฅผ ์ค‘์ง€์‹œํ‚ค๋ ค๋ฉด ์„ค์ • ํŒŒ์ผ์„ ์‚ญ์ œํ•˜์ง€ ๋ง๊ณ  symbolic link ๋ฅผ ์‚ญ์ œํ•ด ์ฃผ๋ฉด ๋˜๋ฏ€๋กœ ์‹ค์ˆ˜๋กœ ์„ค์ • ํŒŒ์ผ์„ ๋‚ ๋ฆด ์ผ์ด ์—†์Šต๋‹ˆ๋‹ค.

rm /etc/nginx/sites-enabled/lesstif.com


์ด์— ๋ฐ˜ํ•ด RHEL ์™€  CentOS ๋Š” ๋‹จ์ผ ์„ค์ • ํŒŒ์ผ(/etc/httpd/conf/httpd.conf, /etc/nginx/nginx.conf)์— ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ๋ฅผ ํฌํ•จํ•œ ๋ชจ๋“  ์„ค์ •์„ ๋„ฃ์–ด์ฃผ๋ฏ€๋กœ ๊ด€๋ฆฌํ•˜๊ธฐ๊ฐ€ ์–ด๋ ต๊ณ  ํŒŒ์ผ์ด ์ปค์งˆ ๊ฒฝ์šฐ ์‹ค์ˆ˜ํ•  ์—ฌ์ง€๊ฐ€ ๋งŽ์•„์ง‘๋‹ˆ๋‹ค.


์„ค์ •

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜๋ฉด RHEL์ด๋‚˜ CentOS ์—์„œ๋„ ์šฐ๋ถ„ํˆฌ ๋ฐฉ์‹๋Œ€๋กœ ์›น ์„œ๋ฒ„์˜ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์„ค์ • ํŒŒ์ผ์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


์›น ์„œ๋ฒ„ ์„ค์ • ์ž‘์—…์ด๋ฏ€๋กœ root ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.



  1. ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ํด๋” ์ƒ์„ฑ

    mkdir /etc/nginx/sites-available/
    mkdir /etc/nginx/sites-enabled/
  2. nginx.conf ํŽธ์ง‘ํ•ฉ๋‹ˆ๋‹ค.

    vi /etc/nginx/nginx.conf
  3. ์ฃผ์š” ์„ค์ •๊ฐ’
    1. worker_processes:๋ณ„๋„์˜ ํ”„๋กœ์„ธ์Šค๋กœ ๊ตฌ๋™๋˜์–ด ์‹ค์ œ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค์˜ ๊ฐฏ์ˆ˜๋กœ ์„œ๋ฒ„ cpu ์˜ core ๊ฐฏ์ˆ˜๋ฅผ ํ™•์ธํ•œ ํ›„ ์ด ์ˆซ์ž๋Œ€๋กœ ์ฃผ๋Š”๊ฒŒ ์ข‹์Šต๋‹ˆ๋‹ค.

      grep processor /proc/cpuinfo | wc -l
    2. worker_connections: ์›Œ์ปค ํ”„๋กœ์„ธ์Šค๋‹น ๋™์‹œ์— ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ์—ฐ๊ฒฐ ๊ฐฏ์ˆ˜. ๊ธฐ๋ณธ ๊ฐ’ 768
    3. max_clients = worker_processes * worker_connections
  4. nginx.conf ์„ค์ • ์˜ˆ์ œ

     Click here to expand...

  5. sites-enabled/example.com ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์˜ˆ์ œ

     Click here to expand...

  6. nginx ์žฌ๊ตฌ๋™

    systemctl restart nginx


serve script ์‚ฌ์šฉ

์œ„์˜ ๊ณผ์ •์„ ์ž๋™ํ™”ํ•˜๊ธฐ ์œ„ํ•ด ๋ณ„๋„์˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ž‘์„ฑํ–ˆ์œผ๋‹ˆ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์•„์„œ ์‹คํ–‰ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

serve-php

php ๋กœ ์›น ์„œ๋น„์Šคํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


  1. script ๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•ฉ๋‹ˆ๋‹ค.

    curl -o serve-php.sh https://gist.githubusercontent.com/lesstif/82c107282241c7a52ad9/raw
    sudo mv serve-php.sh /usr/local/bin/
    sudo chmod +x /usr/local/bin/serve-php.sh 
  2. ์‹คํ–‰ํ•  ๊ฒฝ์šฐ ๋„๋ฉ”์ธ๋ช…(์˜ˆ: mynew.site)๊ณผ webroot (/var/www/my-new-site-webroot)๊ฒฝ๋กœ๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    sudo serve-php.sh mynew.site /var/www/my-new-site-webroot

serve-tomcat

tomcat ์œผ๋กœ ์„œ๋น„์Šคํ•  ๊ฒฝ์šฐ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.


  1. ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

    curl -o serve-tomcat.sh https://gist.githubusercontent.com/lesstif/4d162c4c8df756a65286/raw
    sudo mv serve-tomcat.sh /usr/local/bin/
    sudo chmod +x /usr/local/bin/serve-tomcat.sh
  2. ์‹คํ–‰์€ ๋„๋ฉ”์ธ๋ช…๊ณผ tomcat ์˜ http port ๋ฅผ ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

    sudo serve-tomcat.sh mynew.site 8080


๊ฐ™์ด ๋ณด๊ธฐ


์ฐธ๊ณ 

Related content