๊ฐœ๋ฐœ์ผ์ง€-3 [๐Ÿ”ฅ๊ฐœ๋ฐœํ™˜๊ฒฝ ๊ตฌ์ถ•]

๊น€์„ฑ์ธยท2023๋…„ 9์›” 4์ผ
0

๐Ÿณ ํ”„๋กœ์ ํŠธ ๊ด€๋ฆฌ

GitHub์ฃผ์†Œ

  • ๊ฐœ๋ฐœ์„ ์ง„ํ–‰ํ•  ๋•Œ GitHub๋ฅผ ํ†ตํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜์˜€๋‹ค.
  • ๋‚ด GitHub๊ณ„์ •์— Jatdauree๋ผ๋Š” ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ๋งŒ๋“ค์—ˆ์Œ.
  • ๊ฐ ํŒ€์›๋“ค์„ Collaborator๋กœ ํ•ด๋‹น ๋ ˆํฌ์ง€ํ† ๋ฆฌ์— ์ดˆ๋Œ€ํ•˜์˜€๊ณ  ๋ชจ๋“  ์ปค๋ฐ‹/ ํ‘ธ์‹œ๋Š” ํ•ญ์ƒ ์•„์นจ์— ๋ชจ์—ฌ์„œ ์˜คํ”„๋ผ์ธ์œผ๋กœ ๋‚ด ๊ฐ๋…ํ•˜์— ์ด๋ค„์ง..
  • ์ด๋ ‡๊ฒŒ ํ•œ ์ด์œ ๋Š” ๋‚˜๋จธ์ง€ ํŒ€์›๋“ค์ด GitHub๋ฅผ ์‚ฌ์šฉํ•ด๋ณธ์ ์ด ์—†๊ณ , ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ํ˜น์‹œ๋ผ๋„ ๊ณต๋“ค์—ฌ์„œ ๋งŒ๋“ค์–ด๋†“์€ ํ”„๋กœ์ ํŠธ์— ๋ณ‘ํ•ฉ ์ถฉ๋Œ์ด๋ผ๋„ ๋‚˜๋ฉด ๋งค์šฐ ๊ณค๋ž€ํ•ด์ง€๋‹ˆ๊นŒ..
  • ๋˜ AWS ์„œ๋น„์Šค์—์„œ ์ œ๊ณตํ•˜๋Š” ์„ค์ • ๊ฐ’๊ณผ Secret ๊ฐ’ ๋“ค์„ ํ˜น์‹œ๋ผ๋„ ์‹ค์ˆ˜๋กœ ํŒ€์›๋“ค์ด ์˜ฌ๋ฆด๊นŒ๋ด ํ•ญ์ƒ ์ฃผ์˜ํ•˜๋ฉด์„œ ์ปค๋ฐ‹์„ ์ง„ํ–‰ํ•˜์˜€๋‹ค.
  • ๋งค์ผ API๋ช…์„ธ์„œ๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ๊ฐ ํŒ€์›๋“ค์—๊ฒŒ ์—ญํ•  ๋ถ„๋‹ด์„ ํ–ˆ์ง€๋งŒ,, ์˜ค๋ฅ˜๋‚˜ Java๊ฐœ๋… ๋ถ€์กฑ ๋“ฑ์œผ๋กœ ๊ฐœ๋ฐœ์ด ๋”๋ŽŒ์„œ ๊ตฌ์ƒ‰๋งŒ ๊ฐ–์ถ”๊ณ  ๋‚ด๊ฐ€ ์ตœ์ข… ๋กœ์ง์„ ์™„์„ฑํ•˜๋Š” ๊ฒƒ์ด ๋Œ€๋ถ€๋ถ„์ด์˜€๋‹ค.

๐Ÿณ ๊ฐœ๋ฐœ ํ™˜๊ฒฝ

  • ํ”„๋ ˆ์ž„์›Œํฌ : SpringBoot (Gradle)
  • ์„œ๋น„์Šค ์ œ๊ณต๋ฐฉ๋ฒ• : RestFul API
  • ์ž๋ฐ” SDK ๋ฒ„์ „ : 11.0.15
  • SpringBoot ๋ฒ„์ „ : 2.7.13
  • ์‚ฌ์šฉํ•œ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
    (์•„๋ž˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋กœ์ง ๊ตฌํ˜„์—์„œ ๋‚˜์ค‘์— ์„ค๋ช…ํ•˜๊ฒ ์Œ.)
dependencies {
	implementation 'org.jetbrains:annotations:19.0.0'

	// (1) DB
	implementation group:'mysql', name:'mysql-connector-java', version:'8.0.32'
	implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
	implementation 'org.springframework.boot:spring-boot-starter-jdbc'

	// (2)authenticate
	implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
	implementation 'org.springframework.boot:spring-boot-starter-security'
	testImplementation 'org.springframework.security:spring-security-test'
	implementation "io.jsonwebtoken:jjwt:0.9.1"

	// (3)Lombok
	compileOnly 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'

	// (4)nurigo ๋ฌธ์ž์ธ์ฆ
	implementation 'net.nurigo:sdk:4.2.7'

	// (5)iamport ๊ฒฐ์ œ ์—ฐ๋™
	allprojects {
		repositories {
			//...
			maven { url 'https://jitpack.io' }
		}
	}
	implementation 'com.github.iamport:iamport-rest-client-java:0.2.21'

	// Retrofit2
	//implementation 'com.squareup.retrofit2:retrofit:2.7.2'
	//implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
	//implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'

	// (6)aws cloud s3
	implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
	implementation 'org.springframework.cloud:spring-cloud-aws-context:2.2.6.RELEASE'
	implementation 'org.springframework.cloud:spring-cloud-aws-autoconfigure:2.2.6.RELEASE'

	// (7)spring boot
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-starter-web-services'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'

}

๐Ÿณ ์„œ๋ฒ„ ๋ฐฐํฌ

  • ๋ฐฐํฌ ์„œ๋ฒ„ : AWS EC2 ์ธ์Šคํ„ด์Šค (ํ”„๋ฆฌํ‹ฐ์–ด)
  • IP ์ฃผ์†Œ : AWS Elastic IP
  • ๋„๋ฉ”์ธ ์ฃผ์†Œ : ๊ฐ€๋น„์•„ ๋„๋ฉ”์ธ ์„œ๋น„์Šค (www.insung.shop)
  • ๋ฐฐํฌ ๋ฐฉ๋ฒ• : GitHub SSH ํด๋ก  ๋ฐ ํ’€ (์ฃผ์š” ์‹œํฌ๋ฆฟ ํŒŒ์ผ์€ ์ˆ˜๋™ ๋ฐฐํฌ)

1) AWS EC2 ์ธ์Šคํ„ด์Šค

-> ํฌ์ŠคํŒ… ๋งํฌ(๋„ค์ด๋ฒ„)

  • ์ธ์Šคํ„ด์Šค๋Š” ๋ฆฌ๋ˆ…์Šค Ubuntu ์šด์˜์ฒด์ œ์ด๊ณ , GitHub์—์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ํด๋ก ํ•˜์—ฌ ๋ฐฐํฌํ•˜์˜€๋‹ค.
  • WinSCP ํˆด์„ ์ด์šฉํ•ด์„œ ํ•ด๋‹น ์ธ์Šคํ„ด์Šค์— Putty ํ™˜๊ฒฝ์œผ๋กœ SSH ์ ‘์†์„ ํ†ตํ•ด ์ธ์Šคํ„ด์Šค ๊ด€๋ฆฌ๋ฅผ ํ•˜์˜€๋‹ค.
  • ์„œ๋ฒ„ ๊ตฌํ˜„์„ ์œ„ํ•ด nginx๋ฅผ ์ธ์Šคํ„ด์Šค์— ์„ค์น˜ํ•˜์—ฌ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์—ฐ๊ฒฐ์„ ํ†ตํ•ด ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์œผ๋กœ ํฌํŠธํฌ์›Œ๋”ฉ์„ ์ง„ํ–‰ํ•จ.

2) AWS Elastic IP

3) nginx ์„ค์ •ํŒŒ์ผ

nginx.conf

user www-data;
worker_processes auto;
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 TLSv1.3; # 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/*;

		// ์ด๋ฏธ์ง€ ์š”์ฒญ์„ ์œ„ํ•œ ํด๋ผ์ด์–ธํŠธ ๋ฐ”๋”” ์‚ฌ์ด์ฆˆ ์„ค์ •
        client_max_body_size 10M;
}


#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;
#       }
#}
  • nginx ์„ค์ • default ํŒŒ์ผ
server {
		// (1) ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ
        root /var/www/jatdauree;

		// (2) ๊ธฐ๋ณธ ์—ฐ๊ฒฐ ์ž์›
        index index.html index.htm index.nginx-debian.html;

		// (3) ๋„๋ฉ”์ธ ์ด๋ฆ„
        server_name insung.shop www.insung.shop;

		// (4) ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์„ค์ •
        location / { 
                proxy_pass http://localhost:1920;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
        #       try_files $uri $uri/ =404;
        }

	// (5) HTTPS ๋ณด์•ˆ ์„ค์ •
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate ssl ์ธ์ฆ์„œ ๊ณต์œ ํ‚ค ๊ฒฝ๋กœ
    ssl_certificate_key ์ธ์ฆ์„œ ๊ฐœ์ธํ‚ค ๊ฒฝ๋กœ
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


// (6) ๋ฆฌ๋‹ค์ด๋ ‰์…˜ ์„ค์ •
server {
    if ($host = www.insung.shop) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    if ($host = insung.shop) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 default_server;
        listen [::]:80 default_server;

        server_name insung.shop www.insung.shop;
    return 404; # managed by Certbot

}
  • (1) ํ”„๋กœ์ ํŠธ ๊ฒฝ๋กœ
    : ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋นŒ๋“œ๋˜๊ณ  ์‹คํ–‰๋˜๋Š” ๊ฒฝ๋กœ
  • (2) ๊ธฐ๋ณธ ์—ฐ๊ฒฐ ์ž์›
    : ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ ์‹œ ๋ณด์—ฌ์ค„ ๊ธฐ๋ณธ ๋ทฐ
  • (3) ๋„๋ฉ”์ธ ์ด๋ฆ„
    : ๋„๋ฉ”์ธ ์ฃผ์†Œ ์„ค์ •
  • (4) ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์„ค์ •
    : nginx์„œ๋ฒ„๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ ํฌํŠธ ํฌ์›Œ๋”ฉํ•˜๋Š” ์„ค์ •
  • (5) HTTPS ๋ณด์•ˆ ์„ค์ •
    : CertBot์„ ์ด์šฉํ•˜์—ฌ SSL ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰๋ฐ›๊ณ  HTTPS ๋ณด์•ˆ์„ค์ •
  • (6) ๋ฆฌ๋‹ค์ด๋ ‰์…˜ ์„ค์ •
    : ์„œ๋ฒ„์— HTTPS ์„ค์ •์ด ์•„๋‹Œ ์š”์ฒญ์€ ๋ชจ๋‘ HTTPS๋กœ ๋ฆฌ๋‹ค์ด๋ ‰์…˜

๐Ÿณ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค

AWS RDS๋ฅผ ํ†ตํ•˜์—ฌ ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ์„œ๋ฒ„๋ฅผ ์šด์˜ํ•˜์˜€๋‹ค.
(์ง€๊ธˆ์€ ์Šค๋ƒ…์ƒท ์ฒ˜๋ฆฌ..)


๐Ÿณ ์ด๋ฏธ์ง€ URL

AWS S3 ๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋ฒ„์— ๋“ค์–ด์˜ค๋Š” ์ด๋ฏธ์ง€๋ฅผ ์ €์žฅํ•˜์˜€๋‹ค.


๐Ÿณ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ

๐Ÿฅ—ํŒจํ‚ค์ง€

1) ์ „์ฒด ํ”„๋ ˆ์ž„

jatdauree
	ใ„ด src/main - ๋ฉ”์ธ ํŒจํ‚ค์ง€
    	ใ„ด java
    		ใ„ด com/example/jatdauree
         		ใ„ด config - ์„ค์ • ํŒŒ์ผ ๋ฐ ๋ฐ˜ํ™˜ ํƒ€์ž… ํด๋ž˜์Šค
           	 		ใ„ด secret - ์‹œํฌ๋ฆฟ ํ‚ค ๋ฐ ์•”ํ˜ธํ™” ํŒŒ์ผ (git ignore ์ฒ˜๋ฆฌ)
            	ใ„ด IamPortRestClient - PortOne ๊ฒฐ์ œ ๊ด€๋ จ ํŒจํ‚ค์ง€
            	ใ„ด src
            		ใ„ด domain - ๋„๋ฉ”์ธ ํŒจํ‚ค์ง€
                		ใ„ด app - ๊ตฌ๋งค์ž ๋„๋ฉ”์ธ ํŒจํ‚ค์ง€
                    	ใ„ด kakao - ์นด์นด์˜ค ์œ„์น˜๊ธฐ๋ฐ˜ ์„œ๋น„์Šค ํด๋ž˜์Šค ํŒจํ‚ค์ง€
                    	ใ„ด web - ํŒ๋งค์ž ๋„๋ฉ”์ธ ํŒจํ‚ค์ง€
           		ใ„ด utils - ์•”ํ˜ธํ™” ๋ฐ ์ด๋ฏธ์ง€ ํŒŒ์ผ ์„ค์ • ํด๋ž˜์Šค
            		ใ„ด comein - ๋ณด์•ˆ ๊ด€๋ จ IP ํด๋ž˜์Šค
                	ใ„ด jwt - ์ธ๊ฐ€ ํ† ํฐ ๊ด€๋ จ ํŒจํ‚ค์ง€
     	ใ„ด resources

2) ๋„๋ฉ”์ธ ํŒจํ‚ค์ง€

  • ๊ฐ ๋„๋ฉ”์ธ ๋ณ„ ํŒจํ‚ค์ง€๋ฅผ ๋”ฐ๋กœ ๋งŒ๋“ค๊ณ , ๋‚ด๋ถ€์—๋Š” dao, dto, service, controller ํด๋ž˜์Šค๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•œ ํŒจํ‚ค์ง€๋กœ ๋‚˜๋ˆ ์ ธ์žˆ๋‹ค.
  • ์ด๋ ‡๊ฒŒ ํ•œ ์ด์œ ๋Š” GitHub๋กœ ๊ฐ์ž ๋งก์€ ๋„๋ฉ”์ธ์„ ๋”ฐ๋กœ ์ปค๋ฐ‹ํ•˜์—ฌ ์ถฉ๋Œ์„ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š์œผ๋ ค๊ณ  ํ•˜๊ธฐ ์œ„ํ•จ!
  • ๋ฐ‘์— WebConfig, WebSecurityConfig ํด๋ž˜์Šค๋Š” ๋ณด์•ˆ ์„ค์ •์— ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ ์žˆ๋‹ค. (๋‚˜์ค‘์— ํฌ์ŠคํŒ…)

๐Ÿฅ—application.properties

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ ๋ฐ ๋นŒ๋“œ๋ฅผ ์œ„ํ•œ ํ”„๋กœ์ ํŠธ ๋‚ด ์„ค์ •ํŒŒ์ผ์ด๋‹ค.

server.port = 1920
server.servlet.encoding.charset=UTF-8
server.servlet.encoding.enabled=true
server.servlet.encoding.force=true

# AWS RDS
spring.datasource.url = 
spring.datasource.username= 
spring.datasource.password= 
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# AWS CLOUD & S3
cloud.aws.credentials.access-key=
cloud.aws.credentials.secret-key=
cloud.aws.region.static=
cloud.aws.stack.auto=

cloud.aws.s3.bucket=
cloud.aws.s3.bucket.url=

spring.servlet.multipart.maxFileSize=50MB
spring.servlet.multipart.maxRequestSize=50MB

whois.api.key=
whois.api.uri=

logging.level.com.amazonaws.util.EC2MetadataUtils=error
profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€