๋ฐ˜์‘ํ˜•

# node.js๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํ™˜๊ฒฝ ์…‹ํŒ…์ด ํ•„์š”ํ•˜๋‹ค.


- nginx, node.js, mongodb ์„ค์น˜ ์ˆœ์ด๋‹ค.

- nginx๋Š” ์›น์„œ๋ฒ„๋‹ค. 

- nginx๋Š” ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ํ™œ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. ๋ณดํ†ต์€ ์ค‘๊ฐ„ ๋ผ์šฐํ„ฐ ์—ญํ• ๋กœ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋“ฏ ํ•˜๋‹ค.

- node.js๋Š” ecmascript ๊ธฐ๋ฐ˜ ์–ธ์–ด๋ฅผ ๊ฐ€์ง€๊ณ  ์„œ๋ฒ„๋‹จ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ ํ”Œ๋žซํผ(์™„์ „์ฒด?)์ด๋‹ค.

- node.js๋Š” v8์—”์ง„ ์œ„์—์„œ ๋™์ž‘ํ•œ๋‹ค. (v8์—”์ง„์€ c++๋กœ ๋˜์–ด์žˆ๋‹ค๊ณ  ํ•œ๋‹ด...)

- mongodb๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„์ด๋‹ค.

- nginx, node.js, mongodb๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ํ™˜๊ฒฝ์œผ๋กœ ๋ฆฌ๋ˆ…์Šค ubuntu ์šด์˜์ฒด์ œ๋ฅผ ์„ ํƒํ•˜์˜€๋‹ค.



[0] apt-get ์ตœ์‹ ๋ฒ„์ „ ์—…๋ฐ์ดํŠธ 

 (#apt-get? ์šฐ๋ถ„ํˆฌ, ๋ฐ๋น„์•ˆ ๊ณ„์—ด์˜ ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ ๋ช…๋ น์–ด ๋„๊ตฌ๋ผ๊ณ ํ•จ.  yum์€ ๋ ˆ๋“œํ–‡ ๊ณ„์—ด์—์„œ..)


$ sudo apt-get update


[1] nginx

1) [๋ณดํ†ต ์„ค์น˜] ์„ค์น˜ : sudo apt-get install nginx


* ๋ฒ„์ „ํ™•์ธ : nginx -v


1-1) [**๊ผญ ์•ˆํ•ด๋„ ๋จ] ์ปดํŒŒ์ผ ๋ฐฉ์‹์œผ๋กœ ์„ค์น˜ (์••์ถ•ํŒŒ์ผ์„ ๋ฐ›์•„ ํ’€์–ด์„œ ์ปดํŒŒ์ผ ํ•˜์—ฌ ์„ค์น˜ํ•˜๋Š”๋ฒ•)

 - ์ด๊ฑด ์•ˆํ•ด๋„ ๋˜๋Š” ๋ฒ•์ด๊ธดํ•œ๋ฐ, ๋‚˜์˜๊ฒฝ์šฐ๋Š” nginx echo๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์–ด์„œ ์ด๋ฐฉ๋ฒ•์œผ๋กœ ์„ค์น˜๋ฅผ ์‹œ๋„ํ–ˆ๋‹ค.

 - echo ๋ชจ๋“ˆ ์žˆ์œผ๋ฉด nginx ํ•จ์ˆ˜ ๋‚ด์—์„œ ํ˜ธ์ถœ์—ฌ๋ถ€ ํ™•์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 http://astinchoi.github.io/2018/02/01/nginx_install_with_echo_nginx_module.html

 ์œ„์˜ ๋งํฌ๋ฅผ ์‘์šฉํ–ˆ๊ณ , 


 ๋‚˜๋Š” ์ด๋ ‡๊ฒŒ ํ–ˆ๋‹ค.

 $ apt-get install gcc, unzip, make, g++


 $ wget http://nginx.org/download/nginx-1.12.2.tar.gz

 $ tar -xvzf nginx-1.12.2.tar.gz

 $ wget https://github.com/openresty/echo-nginx-module/archive/v0.61.zip

 $ unzip v0.61.zip

 $ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz

 $ tar -zxf pcre-8.42.tar.gz

 $ wget http://www.openssl.org/source/openssl-1.0.2p.tar.gz

 $ tar -zxf openssl-1.0.2p.tar.gz

 $ wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

 $ unzip master.zip

 $ wget http://zlib.net/zlib-1.2.11.tar.gz

 $ tar -zxf zlib-1.2.11.tar.gz

 $ cd nginx-1.12.2

 

 $ ./configure --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre=/root/pcre-8.42 --with-zlib=/root/zlib-1.2.11 --add- module=/root/echo-nginx-module-0.61 

>> ์ฐธ๊ณ ๋กœ ๊ฒฝ๋กœ๊ฐ™์€๊ฑด ์กฐ๊ธˆ ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.


 $ make -j2

 $ make install


 ์ด๋ ‡๊ฒŒ ์ปดํŒŒ์ผ๋ฐฉ์‹์œผ๋กœ ์„ค์น˜๋ฅผ ํ–ˆ๋‹ค......



2) ์‹คํ–‰ : sudo service nginx start    

  ~ ์•„๋‹ˆ๋ฉด.... sudo /etc/init.d/nginx start

  ~ ์ค‘์ง€๋Š” stop, ์žฌ์‹œ์ž‘์€ restart, ์ƒํƒœ๋Š” status


โ€ป service ๋ช…๋ น์–ด๊ฐ€ ์‹คํ–‰์ด ์•ˆ๋œ๋‹ค๋ฉด /lib/systemd/system/ ์„ ๋ณด๋ผ. (nginx.service ํŒŒ์ผ ์ฐพ์•„๋ณด๊ธฐ)

โ€ป /etc/init.d/nginx ๊ฐ€ ์‹คํ–‰์ด ์•ˆ๋œ๋‹ค๋ฉด /etc/init.d์— nginx ํŒŒ์ผ์„ ์‚ดํŽด๋ณด๋ผ. (์—†์œผ๋ฉด ์ฐพ์•„์„œ ๋งŒ๋“ค๋˜๊ฐ€ ํ•ด์•ผํ•œ๋‹ค.)


3) ์‹คํ–‰ ํ™•์ธ : ip ์ฃผ์†Œ ์ ‘๊ทผ์œผ๋กœ ํ™•์ธ(http)

 - http ์ ‘๊ทผ์ด ์•ˆ๋˜๊ฑฐ๋“  ํ•ด๋‹น ํฌํŠธ(80)์ด ์—ด๋ ค์žˆ๋Š”์ง€ ํ™•์ธํ•˜์—ฌ์•ผ ํ•œ๋‹ค.


4) ์„ค์ • : /etc/nginx/sites-enabled ์ด๋™ํ•˜์—ฌ test.conf ํŒŒ์ผ์ƒ์„ฑ (ํŒŒ์ผ๋ช…์€ ์ƒ๊ด€์—†์Œ)

 - ์™ธ๋ถ€ ์„œ๋ฒ„์—์„œ ์ƒ์„ฑํ•  ๊ฒฝ์šฐ ๋‚ด๋ถ€ ํฌํŠธ๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋ฒ„์‹คํ–‰

 ---- test.conf ๋‚ด์šฉ ----

server {

    listen       80;

    server_name  localhost;


    location / {

        proxy_set_header Host $http_host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_set_header X-NginX-Proxy true;


        proxy_pass http://localhost:3000/; <----์‚ฌ์šฉํ•  ๋‚ด๋ถ€ ํฌํŠธ ์ž…๋ ฅ

        proxy_redirect off;

        index index.jsp index.html index.php;

    }


    error_page   500 502 503 504  /50x.html;

    location = /50x.html {

        root   html;

    }

}

 ---- ---- ---- ---- ----

 - ์ด๋ ‡๊ฒŒ ๋˜๋ฉด, ์™ธ๋ถ€์—์„œ http://์„œ๋ฒ„์ฃผ์†Œ ๋กœ ์ ‘๊ทผ์‹œ servcer -> location / ํ•จ์ˆ˜๋ฅผ ํƒ„๋‹ค.


[2] node.js

1) ์„ค์น˜ : sudo apt-get install -y nodejs

* ๋ฒ„์ „ํ™•์ธ : node -v


[2-1] npm ์ตœ์‹ ๋ฒ„์ „ ์˜ฌ๋ฆฌ๊ธฐ

1) ์„ค์น˜ : sudo npm install -g npm

* ๋ฒ„์ „ํ™•์ธ : npm -v


[3] mongodb

1) ์„ค์น˜ : sudo apt-get install mongodb

* ๋ฒ„์ „ํ™•์ธ : mongo --version

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:


์—๋Ÿฌ๋‚จ (ใ… ใ… )

db๋ช… ์ž˜๋ชป๋˜์–ด์žˆ์–ด์„œ ๋‚ฌ์—ˆ์Œ... db๋ช… ๊ณ ์ณ์ฃผ๋‹ˆ ํ•ด๊ฒฐ!

...

root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database '์ž˜๋ชป๋œDB๋ช…'
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)


๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
@ reverse 
 - ๋ฐฐ์—ด.reverse() : ๋ฐฐ์—ด ๋’ค์ง‘๊ธฐ
var test = [1,2,3,4,5]; 
test.reverse(); //test=[5,4,3,2,1] 

@ split 
 - ๋ฌธ์ž.split("๋Š๋Š”๋ฌธ์ž์—ด") : ๋ฌธ์ž์—ด ๋ฐฐ์—ดํ™” ํ•˜๊ธฐ
var testString = "1,2,3,4,5";
testString.split(",");// ["1", "2", "3", "4", "5"]

@ shift 
- ๋ฐฐ์—ด.shift("๋ฌธ์ž") : ๋ฐฐ์—ด ์ฒซ๋ฒˆ์งธ ๊ฐ’ ๋นผ๊ธฐ([๋ฐฉํ–ฅ:<--]์™ผ์ชฝ์œผ๋กœ ๋ฐ€๋ ค์ง)
var test = [1,2,3,4,5];
test.shift();//1
test.shift();//2
test.shift();//3
test.shift();//4
test.shift();//5
test.shift();//undefined
console.log(test);//

var testA = [6,7,8,9];
testA.shift();//6
console.log(testA);//(3) [7, 8, 9]

@ unshift 
- ๋ฐฐ์—ด.unshift("๋ฌธ์ž") : ๋ฐฐ์—ด๊ฐ’ ์ฒซ๋ฒˆ์งธ์— ๊ฐ’ ์ถ”๊ฐ€([๋ฐฉํ–ฅ:-->]์˜ค๋ฅธ์ชฝ์œผ๋กœ ๋ฐ€๋ ค์ง)
var test = [1,2,3]
test.unshift()
console.log(test);// (3) [1, 2, 3]
test.unshift(4) 
console.log(test); // (4) [4, 1, 2, 3]
test.unshift(6)
console.log(test);// (5) [6, 4, 1, 2, 3]

@ push 
- ๋ฐฐ์—ด.push(๋„ฃ๋Š”๊ฐ’) : ๋ฐฐ์—ด๊ฐ’ ๋์š”์†Œ์— ๊ฐ’ ์ถ”๊ฐ€
var test = [1,2,3,4,5,6];
test.push(7); //7
console.log(test); // (7) [1, 2, 3, 4, 5, 6, 7]

@ pop 
- ๋ฐฐ์—ด.pop() : ๋ฐฐ์—ด๋’ค์— ๋ฐฐ์—ด๊ฐ’ ๋นผ๊ธฐ
var test = [1,2,3,4,5,6];
test.push(); //6
console.log(test); // (5) [1, 2, 3, 4, 5]

@ splice 
- ๋ฐฐ์—ด.splice(์ˆœ์„œ,๊ฐฏ์ˆ˜) : ์ˆœ์„œ์œ„์น˜๋ถ€ํ„ฐ ๊ฐฏ์ˆ˜๊นŒ์ง€ ๋ฒ„๋ฆผ
var test = [1,2,3,4,5,6,7,8,9];
test.splice(0,2)// (2) [1, 2] : 0๋ฒˆ์งธ์—์„œ 2๊ฐœ ๋ฒ„๋ฆผ
console.log(test)// (7) [3, 4, 5, 6, 7, 8, 9]
test.splice(2,5)// (5) [5, 6, 7, 8, 9] : 012๋ฒˆ์งธ์—์„œ5๊ฐœ๋ฒ„๋ฆผ
console.log(test)// (2) [3, 4]

@ concat 
- A๋ฐฐ์—ด.concat(B๋ฐฐ์—ด) : ๋ฐฐ์—ดํ•ฉ์น˜๊ธฐ(A+B)
var A = [5,6,7]
var B = [1,2,3]
A.concat(B) //(6) [5, 6, 7, 1, 2, 3]

@ join 
- ๋ฐฐ์—ด.join("๋ฌถ๋Š”๋ฌธ์ž์—ด") : ๋ฐฐ์—ด์„ ๋ฌถ๋Š”๋ฌธ์ž์—ด๋กœ ์—ฐ๊ฒฐํ•˜์—ฌ ๋ฌธ์ž์—ด๋กœ ๋ณ€๊ฒฝ
var test = [1,2,3,4,555,6]
test.join(",") //"1,2,3,4,555,6"
test.join("555")//"15552555355545555555556"
test.join("1")//"1121314155516"
test.join("-")//"1-2-3-4-555-6"

@ sort 
- ๋ฐฐ์—ด.sort() : ๋ฐฐ์—ด ์ •๋ ฌ
var test = [4,3,6,1,2]
test.sort() //(5) [1, 2, 3, 4, 6]

@ substr 
- ๋ฌธ์ž.substr(์ˆœ์„œ,๊ฐฏ์ˆ˜) : ์ˆœ์„œ๋ถ€ํ„ฐ ๊ฐฏ์ˆ˜๊นŒ์ง€ ์ถ”์ถœ
var test = 'Hello, my world!!';
test.substr(2,3) //"llo"//012๋ฒˆ์งธ์—์„œ3๊ฐœ
test.substr(0,3)//"Hel"//0๋ฒˆ์งธ์—์„œ3๊ฐœ
test.substr(0,5) //"Hello" //0๋ฒˆ์งธ์—์„œ5๊ฐœ
test.substr(5,5)//", my " //012345๋ฒˆ์งธ์—์„œ 5๊ฐœ



๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

Error [ERR HTTP HEADERS_SENT]: Cannot set headers after they are sent to the client



response.send() ํ•œ๋ฒˆ๋งŒ!

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์ฐธ๊ณ ํ•จ : https://stackoverflow.com/questions/19051041/cannot-overwrite-model-once-compiled-mongoose



์—๋Ÿฌ๊ฐ€๋‚˜์„œ ๋ณด๋‹ˆ

์Šคํ‚ค๋งˆ ์„ ์–ธ์„ ํ•œ๋ฒˆ๋งŒ ๋กœ๋“œํ•˜๋ผ๋Š” ๋œป์ธ๊ฑฐ๊ฐ™์•˜๋‹ค.


์ „์—ญ์—๋‹ค๊ฐ€ ์„ ์–ธ์„ ํ•ด๋†“๋“ ,

์ตœ์ดˆ ์‹คํ–‰ ํ•จ์ˆ˜(์ƒ์„ฑ์ž) ๊ฐ™์€๊ณณ์— 

์ตœ์ดˆ ํ•œ๋ฒˆ๋งŒ ๋ถ€๋ฅด๋‹ˆ ์—๋Ÿฌ๊ฐ€ ์•ˆ๋‚œ๋‹ค.



๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

์ž˜๋˜๋˜ ํ”„๋กœ์ ํŠธ์˜€๋Š”๋ฐ,


์„œ๋ฒ„๋ฅผ ์‹คํ–‰ํ•˜๋‹ˆ, 500์—๋Ÿฌ๋ฅผ ๋ฑ‰์œผ๋ฉด์„œ

Servlet.init() for servlet appServlet threw exception


์ด๋Ÿฐ๋ฌธ๊ตฌ์™€ํ•จ๊ป˜,

Error creating bean with name 'org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean#0

์ด๋Ÿฌํ•œ ์—๋Ÿฌ๊ฐ€ ๋‚˜์™€์„œ ์ฐพ๋˜์ค‘

- ์ฐธ๊ณ  : https://stackoverflow.com/questions/35986200/error-creating-bean-with-name-org-springframework-validation-beanvalidation-opt


์œ„์˜ ์‚ฌ์ดํŠธ์˜ ๋‚ด์šฉ์œผ๋กœ ํ•ด๊ฒฐํ•จ!



๊ฐ€๋” *.jar ๋ฒ„์ „์ด ์•ˆ๋งž๊ฑฐ๋‚˜(๋ฒ„์ „์ด ์˜ฌ๋ผ๊ฐ€๊ฑฐ๋‚˜) ํ•˜๋ฉด ์ €๋Ÿฐ์‹์œผ๋กœ ์•ˆ๋งž๋Š”๋‹ค๊ณ  ์—๋Ÿฌ๋ฅผ ๋‚ด๋ฑ‰๋Š” ๋ชจ์–‘


pom.xml์„ 

<dependency> 

<groupId>org.hibernate</groupId> 

<artifactId>hibernate-validator</artifactId> 

<version>5.2.4.Final</version>

</dependency> 


์œผ๋กœ ๋งž์ถฐ์ฃผ๊ณ , 


dtoํŒจํ‚ค์ง€์˜ ๊ด€๋ จ ํด๋ž˜์Šค๋„ ๋งž์ถฐ์ฃผ๋‹ˆ ํ•ด๊ฒฐ!

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๋กœ์ปฌ์—์„œ ์‹คํ–‰๋จ์„ ํ™•์ธํ•˜์˜€๋‹ค.


์ด๋ฒˆ์—” ๋ฆฌ๋ˆ…์Šค ์„œ๋ฒ„์—์„œ ์‹คํ–‰ ํ•ด ๋ณผ ์ƒ๊ฐ์ด๋‹ค.


0. ์‚ฌ์ „ ์ค€๋น„์‚ฌํ•ญ


0-0. ๋ฆฌ๋ˆ…์Šค ์„œ๋ฒ„(๋‚˜์˜ ๊ฒฝ์šฐ๋Š” [AWS EC2 - ubuntu]๋ฅผ ์ด์šฉ)

 * ์ฐธ๊ณ  : http://mungmange.tistory.com/59?category=741355,


0-1. java8์„ค์น˜

 * ์ฐธ๊ณ  : https://zetawiki.com/wiki/%EC%9A%B0%EB%B6%84%ED%88%AC_Java_8_%EC%84%A4%EC%B9%98

          : http://bluexmas.tistory.com/734 << ๋‚˜๋Š” ์ด๊ฑธ ์ฐธ๊ณ ํ•จ


  $ add-apt-repository ppa:webupd8team/java
  $ apt-get update
  $ apt-get install oracle-java8-installer
  $ java -version
  $ apt-get install oracle-java8-installer
  $ java -version


0-2. tomcat 7.0์„ค์น˜

* ์ฐธ๊ณ  : https://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_%ED%86%B0%EC%BA%A37_%EC%BB%B4%ED%8C%8C%EC%9D%BC_%EC%84%A4%EC%B9%98

http://kingle1024.tistory.com/60 << ๋‚˜๋Š” ์ด๊ฑธ ์ฐธ๊ณ ํ•จ


 $ apt-get install tomcat7
 $ service tomcat7 start
 $ sudo ln -s /usr/lib/jvm/java-8-oracle/ /usr/lib/jvm/default-java
 $ service tomcat7 start


๋ญ ๊ฒ€์ƒ‰ํ•˜๋ฉด ๋งŽ์ด ๋‚˜์˜จ๋‹ค.




1. ๋ฆฌ๋ˆ…์Šค 8080ํฌํŠธ๋ฅผ ์—ด์–ด๋ผ.


tomcat ๊ธฐ๋ณธ ํฌํŠธ๋Š” 8080์œผ๋กœ ์„ค์ •๋˜์–ด์žˆ๋‹ค.

๋‚˜๋Š” 8080์œผ๋กœ ์„ค์ •์„ ํ•ด๋†“๊ณ  ์‹คํ–‰ํ•˜์˜€๋‹ค.


์ฐธ๊ณ ๋กœ AWS๋ฅผ ์‚ฌ์šฉํ•œ ๋‚˜๋Š” AWS ๋Œ€์‹œ๋ณด๋“œ์— ๋“ค์–ด๊ฐ€์„œ ์„ค์ •ํ•ด์ฃผ์—ˆ๋‹ค.


โ€ป ์™ ๋งŒํ•˜๋ฉด ์ฝ˜์†”๋‚ด์—์„œ ๋ฐฉํ™”๋ฒฝ ์„ค์ •์„ ํ•˜์ง€ ๋ง๊ธฐ๋ฅผ

--> ์˜ˆ์ „์— ์ฝ˜์†”๋กœ ๋ฐฉํ™”๋ฒฝ ์ž˜๋ชป ๊ฑด๋“ค์˜€๋‹ค๊ฐ€ ์ ‘์†์•ˆ๋˜์„œ EC2 ์ƒˆ๋กœ ์„ค์น˜ํ•œ ์ ์ด ์žˆ์—ˆ๋‹ค. (ใ… ใ… )


* ์ฐธ๊ณ  : http://mungmange.tistory.com/66?category=741355 (์‰ฝ๋‹ค)


ํฌํŠธ๋ฅผ ์—ฐ ํ›„, ํ•ด๋‹น URL์„ ์ ‘์†ํ•ด๋ณธ๋‹ค.

์ด๋Ÿฌํ•œ ํ˜•ํƒœ์ผ ๊ฒƒ์ด๋‹ค.


http://๋ฆฌ๋ˆ…์Šค์ฃผ์†Œ:8080

2. war ํŒŒ์ผ ์ง‘์–ด๋„ฃ๊ธฐ.


์œ„์˜ ๊ทธ๋ฆผ์—๋„ ๋‚˜์™€์žˆ์ง€๋งŒ, ์ € It works ! ~~ ๋‚˜์˜ค๋Š” ํŽ˜์ด์ง€์˜ ๊ฒฝ๋กœ๋Š”

/var/lib/tomcat7/webapps/ROOT/index.html ์ด๋‹ค. (์œ„์— ๋‚˜์™€์žˆ๋‹ค.)


ํ•ด๋‹น์œ„์น˜๊ฐ€ ํ†ฐ์บฃ ์‹คํ–‰ ํ–ˆ์„ ๋•Œ์˜ ๊ธฐ๋ณธ ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ์ด๋‹ค.

์ด๊ฑด server.xml์—์„œ ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•˜๋‹ค. 


๋‚˜๋Š” 

/var/lib/tomcat7/webapps/ROOT 

๊ฒฝ๋กœ์— mungmang_java.war ์„ ์ง‘์–ด๋„ฃ๊ณ , ์••์ถ•์„ ํ’€์—ˆ๋‹ค.

์ง‘์–ด๋„ฃ๋Š”๊ฑด ํŒŒ์ผ์ฆ๋ผ ํ”„๋กœ๊ทธ๋žจ(SFTP ์—ฐ๊ฒฐ ํ”„๋กœ๊ทธ๋žจ) ์ด์šฉ.


$ unzip mungmang_java.war -d /var/lib/tomcat7/webapps/ROOT/mungmang_java


โ€ป ๋งŒ์•ฝ unzip ์ด ubuntu์— ์„ค์น˜๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฉด ์„ค์น˜ํ•ด๋ผ (apt-get install unzip)



3. server.xml๋ฅผ ์ฐพ์•„ context๊ฒฝ๋กœ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.


$ find / -name 'server.xml' 
$ vi /ํ†ฐ์บฃ์œ„์น˜๊ฒฝ๋กœ/server.xml


ํ•ด๋‹น ์œ„์น˜๋ฅผ ์ฐพ์•„ ๋นจ๊ฐ„๊ธ€์”จ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•œ๋‹ค.

      <Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">

        <Context docBase="./ROOT/mungmang_java" path="/mungmang_java" reloadable="true"/>

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

               prefix="localhost_access_log." suffix=".txt"

               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>


๊ทธ๋ฆฌ๊ณ  tomcat ์žฌ์‹œ์ž‘


$ service tomcat7 restart


โ€ป ๋งŒ์•ฝ appBase๊ฒฝ๋กœ๋ฅผ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์œผ๋ฉด


      <Host name="localhost"  appBase="/var/abcd"

            unpackWARs="true" autoDeploy="true">

        <Context docBase="mungmang_board.war" path="/springpj" reloadable="true"/>

        <Context docBase="mungmang_java.war" path="/mungmang_java" reloadable="true"/>


        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"

               prefix="localhost_access_log." suffix=".txt"

               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>


# ์ฐธ๊ณ  : http://dimdim.tistory.com/entry/Tomcat-WAR-%ED%8C%8C%EC%9D%BC-%EB%B0%B0%ED%8F%AC-%EC%82%BD%EC%A7%88%EC%97%90-%EB%8C%80%ED%95%9C-%EC%A0%95%EB%A6%AC



4. ์‹คํ–‰ํ•ด๋ณธ๋‹ค.


http://๋ฆฌ๋ˆ…์Šค์ฃผ์†Œ:8080/mungmang_java/test.jsp


โ€ป ๋งŒ์•ฝ jstl ๊ด€๋ จ ์—๋Ÿฌ๊ฐ€ ๋‚˜๊ฑฐ๋“ ,

/var/lib/tomcat7/webapps/ROOT/mungmang_java/WEB-INF/lib ์œ„์น˜์— jstl-1.2.jar ํŒŒ์ผ์„ ๋„ฃ์–ด์ฃผ์ž.




-- ๋

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

โ€ป ์‚ฌ์ „ ์ค€๋น„์‚ฌํ•ญ


๋กœ์ปฌPC์ค€๋น„->tomcat, java์„ค์น˜->์ดํด๋ฆฝ์Šค์„ค์น˜


์ด๊ฑด๋ญ ๊ธฐ๋ณธ์œผ๋กœ ๋˜์–ด์žˆ์œผ๋ฆฌ๋ผ ์ƒ๊ฐํ•œ๋‹ค.


---



1. ๋กœ์ปฌ์„œ๋ฒ„์—์„œ ์›นํ”„๋กœ์ ํŠธ ๊ฐœ๋ฐœ


์ธํ”„๋Ÿฐ ๊ฐ•์ขŒ๋ฅผ ์ฐธ๊ณ  ํ•˜์˜€๋‹ค. 


โ€ป ์ฐธ๊ณ  : https://www.inflearn.com/course-status-2/



1-1. ์ดํด๋ฆญ์Šค์—์„œ ๋‹ค์ด๋‚˜๋ฏน ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ



๊ทธ ํ›„, [Project name] ์ž…๋ ฅ ํ›„ ํ•˜๋‹จ์˜ [Finish ๋ฒ„ํŠผ] ํด๋ฆญ!


- Static Web Project : ๋™์  ์š”์†Œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์€ ํ”„๋กœ์ ํŠธ(HTML)

- Dynamic Web Project : ๋™์  ์š”์†Œ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ(JSP, Servlet ..)



1-2. ํŒŒ์ผ ๊ตฌ์กฐ ์ƒ์„ฑ


์ธํ”„๋Ÿฐ ๊ฐ•์˜๋ฅผ ์ฐธ๊ณ  ํ•˜์˜€๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์ด ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์˜€๋‹ค.



ํŒจํ‚ค์ง€๋ฅผ command, dto, frontcontroller ๋กœ ๊ตฌ๋ถ„ ํ•˜์˜€๋‹ค. 

(DB๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋‹ค. ๊ทธ๋ž˜์„œ dao๊ฐ€ ์—†๋‹ค.)


์•„๋ž˜๋Š” ์†Œ์ŠคํŒŒ์ผ์ด๋‹ค. (*.war ํŒŒ์ผ๋กœ ์ƒ์„ฑํ•˜์˜€๋‹ค.)

mungmang_java.war


๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.




2. ๋กœ์ปฌ์„œ๋ฒ„์—์„œ ์‹คํ–‰ํ•ด๋ณด๊ธฐ


2-1. tomcat ์‹คํ–‰ํ•ด๋ณด๊ธฐ


์ดํด๋ฆฝ์Šค์—์„œ tomcat์„ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค.

์‹คํ–‰ ์ „, server.xml ํŒŒ์ผ ์—ด์–ด์„œ ๋นจ๊ฐ„๊ธ€์”จ๋ถ€๋ถ„์„ ์ถ”๊ฐ€ํ•˜์ž.



<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

      <Context docBase="mungmang_java" path="/mungmang_java" reloadable="true" source="org.eclipse.jst.jee.server:mungmang_java"/> <!-- ์ถ”๊ฐ€ -->

</Host>


๋˜๋Š” 


์ด๋Ÿฐ๋ฐฉ์‹์œผ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ด๋„ ๋œ๋‹ค.


๊ทธ๋ฆฌ๊ณ ๋‚˜์„œ test.jsp ํŒŒ์ผ์„ ์‹คํ–‰!


๊ฒฝ๋กœ๋Š” http://localhost:8080/mungmang_java/test.jsp


๊ฒฐ๊ณผ๋Š” http://localhost:8080/mungmang_java/result.do


โ€ป ๋งŒ์•ฝ jstl ๊ด€๋ จ ์—๋Ÿฌ๊ฐ€ ๋‚œ๋‹ค๋ฉด, 

C:\ํ†ฐ์บฃ๊ฒฝ๋กœ\lib ์œ„์น˜์— jstl-1.2.jarํŒŒ์ผ์„ ์ฃผ์ž…์‹œ์ผœ ์ค€๋‹ค.


* jstl ๋‹ค์šด ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ : 

https://www.google.co.kr/search?ei=QAFjW4SMGInk8wWJhon4CQ&q=jstl+%EB%8B%A4%EC%9A%B4&oq=jstl+%EB%8B%A4%EC%9A%B4&gs_l=psy-ab.3..0j0i5i30k1j0i8i30k1l6j0i30k1.2755704.2758882.0.2759275.12.12.0.0.0.0.361.1377.0j6j1j1.9.0....0...1.1j4.64.psy-ab..4.8.1342.6..0i10k1j35i39k1j0i67k1.115.ONpoo-7ivtE



3. war ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜์ž.


์œ„์— mungmang_java.war ํŒŒ์ผ์„ ๋งŒ๋“ค์—ˆ๋˜ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.


ํ•ด๋‹น ํ”„๋กœ์ ํŠธ ์˜ค๋ฅธ์ชฝ ๋ฒ„ํŠผ ํด๋ฆญ -> Export -> War File ํด๋ฆญ



Finish!


๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

#ubuntu์—์„œ django


---------------------------------------------------------------------------------

# ์ฐธ๊ณ  

https://tutorial.djangogirls.org/ko/installation/

http://incoffee.tistory.com/6 ---> ์ด๊ฑฐ ๋ณด๊ณ  ํ•จ  

https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html

http://pythonstudy.xyz/python/article/303-Django-%EC%84%A4%EC%B9%98

https://docs.djangoproject.com/ko/2.0/intro/tutorial01/


# ๋ฒ„์ถ”์–ผ ํ™˜๊ฒฝ ์„ค์ • ๊ด€๋ จ

https://beomi.github.io/2016/12/28/HowToSetup-Virtualenv-VirtualenvWrapper/

---------------------------------------------------------------------------------


[0] apt-get ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ

$ sudo apt-get update && apt-get upgrade -y


[1] python-pip, python-dev ์„ค์น˜

$ sudo apt-get install python-pip python-dev
$ sudo apt-get install python3-pip python3-dev


[2] ํ™•์ธ

$ pip -V
$ pip3 -V


[3] pip์œผ๋กœ virtualenv virtualenvwrapper ์„ค์น˜

$ pip install virtualenv virtualenvwrapper

$ pip3 install virtualenv virtualenvwrapper


[4] virtualenv ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ virtualenv --python=ํŒŒ์ด์ฌ๋ฒ„์ „ ๊ฐ€์ƒํ™˜๊ฒฝ์ด๋ฆ„

# ex)

$ virtualenv --python=python3.5 ๊ฐ€์ƒํด๋”

$ virtualenv --python=python2.7 ๊ฐ€์ƒํด๋”


[5] ๊ฐ€์ƒํ™˜๊ฒฝ ์‹คํ–‰

$ cd ๊ฐ€์ƒํด๋”/bin/

$ source activate


[6] ์žฅ๊ณ ์„ค์น˜

- pip์ด ์ตœ์‹  ๋ฒ„์ „์ธ์ง€ ํ™•์ธ

$ pip install --upgrade pip

$ pip install django~=1.11.0


[7] ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ cd ๊ฐ€์ƒํด๋”

$ django-admin startproject mysite .


[8] ์žฅ๊ณ  ํ”„๋กœ์ ํŠธ ํ™˜๊ฒฝ์„ค์ • ๋ณ€๊ฒฝ

mysite/settings.py


TIME_ZONE = 'Asia/Seoul'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

ALLOWED_HOSTS = ['127.0.0.1', '.pythonanywhere.com']


์ถ”๊ฐ€ ๋ฐ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์…‹ํŒ… >> ์ด๋ฏธ ๋‚ด๋ถ€์— sqlite3์ด ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๊ณ  ํ•จ.

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),

    }

}


[9] ์‹คํ–‰ (python ์œผ๋กœ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ uWSGI ์œผ๋กœ ์‹คํ–‰)

$ python manage.py migrate ---> ์„œ๋ฒ„ ์ž‘๋™ ํ™•์ธ

$ python manage.py runserver ---> ์„œ๋ฒ„์‹คํ–‰

[9-1] uWSGI๋ฅผ virtualenv์— ์„ค์น˜

$ pip install uwsgi

[9-2] uWSGI ์‹คํ–‰

$ uwsgi --socket :8001 --wsgi-file test.py

[9-3] django ํ”„๋กœ์ ํŠธ ์‹คํ–‰

$ python manage.py runserver

$ uwsgi --socket :8001 --module mysite.wsgi --> ์‹คํ–‰ ๋˜์—ˆ์Œ

>> (test) root@mungmange:/var/www/dev/git_project/dev_toy/py/test/mysite # uwsgi --socket :8001 --module mysite.wsgi

$ uwsgi --http :8001 --module mysite.wsgi #uwsgi --socket :8001 --wsgi-file test.py



[10] nginx ์Šคํฌ๋ฆฝํŠธ

-------------------------------------------

upstream django{

    server localhost:8001;

}

server {


    listen       80;

    server_name  localhost;


    charset utf-8;


location ~ /d {

    uwsgi_pass  django;

include     uwsgi_params; # the uwsgi_params file you installed

}

}

-------------------------------------------

$ service nginx restart


[11] ์ฐธ๊ณ ๋กœ setting.py ํŒŒ์ผ ์ˆ˜์ • ํ›„

$ python manage.py migrate ํ•ด์ฃผ๊ธฐ



[12] ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ

$ python manage.py ๊ฐ€์ƒํด๋” blog



----------------------------------------------------------------------------------------------------------------

# python ์ฟผ๋ฆฌ์…‹


[1] shell ์‹คํ–‰

(test) root@mungmange:/var/www/dev/git_project/dev_toy/py/test/mysite# python manage.py shell



[2] ๊ฐ์ฒด ์กฐํšŒ

>>> from blog.models import Post

>>> Post.objects.all()

<QuerySet [<Post: aa>, <Post: aa>, <Post: aa>, <Post: ad>, <Post: sdf>]>


๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๋ฉ”์ด๋ธ ํ”„๋กœ์ ํŠธ ๋นŒ๋“œ ์ค‘์—


Invalid LOC header


๋ผ๋Š” ์—๋Ÿฌ๊ฐ€ ๋‚˜์™€์„œ ๋ญ”๊ฐ€ํ•˜๊ณ  ์ฐพ์•„๋ณด์•˜๋Š”๋ฐ,


jar ํŒŒ์ผ์ด ๊นจ์ ธ์„œ ํ˜น์€ jar ํŒŒ์ผ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์–ด์„œ ๋‚˜๋Š” ์—๋Ÿฌ๋ผ๊ณ  ํ•œ๋‹ค.


๋ฐฉ๋ฒ•์œผ๋กœ๋Š” ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํŒŒ์ผ(*.jar)์„ ์ฐพ์•„ ์ง€์šฐ๊ณ  ๋‹ค์‹œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(*.jar)๋ฅผ ๋ถˆ๋Ÿฌ์™€๋ผ์˜€๋‹ค.

(๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜จ๋‹ค๋Š”๊ฑด pom.xml ์— ๋‹ค์‹œ ์„ค์ •์„ ํ•˜์—ฌ ๋ถˆ๋Ÿฌ์˜ค๋ผ๋Š” ์–˜๊ธฐ์ผ ๊ฒƒ์ด๊ฒ ์ง€)



์ง€์›Œ๋ณด๊ณ ๋„ ์•ˆ๋˜๋ฉด, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฒ„์ „ํ™•์ธ๋„ ํ•ด๋ณผํ•„์š”๊ฐ€ ์žˆ์„๊ฒƒ์ด๋‹ค.


๋‚˜์˜๊ฒฝ์šฐ๋Š”, aspectj ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— ๋Œ€ํ•œ ์—๋Ÿฌ์˜€๋Š”๋ฐ,

์ž๋ฐ”๋ฒ„์ „์ด๋ž‘ aspectj๋ฒ„์ „์ด๋ž‘ ์•ˆ๋งž์•„์„œ ๊ทธ๋žฌ๋‹ค.


-- pom.xml

<properties>

<java-version>1.8</java-version>

<org.springframework-version>4.0.4.RELEASE</org.springframework-version>

<org.aspectj-version>1.8.1</org.aspectj-version> <!-- 1.6.0์—์„œ 1.8.1๋กœ ์˜ฌ๋ ค์คŒ-->

<org.slf4j-version>1.6.6</org.slf4j-version>

</properties>


๊ทธ๋žฌ๋”๋‹ˆ ์—๋Ÿฌ๊ฐ€ ์—†์–ด์กŒ๋‹ค.


์ฐธ๊ณ  : https://www.slipp.net/wiki/pages/viewpage.action?pageId=1343532

๋ฐ˜์‘ํ˜•

+ Recent posts