[AWS 무료 서버구축-13/18] Nginx Springboot 연동
Setup/aws2021. 7. 25. 15:53
Nginx Springboot 연동
http://goodsaem.ml/spring 로 접속하면 springboot가 응답하도록 nginx 설정을 변경하겠습니다
nginx 설정파일 수정
아래 명령어로 nginx 설정 파일을 수정 합니다.
ubuntu@goodsaem:~$ sudo vi /etc/nginx/conf.d/default.conf
아래와 같이 /spring 요청이 오면 14~17 라인 설정에 따라 springboot로 보내는 설정입니다. 그외 전체 nginx 설정이 있으니 참고 하시기 바랍니다
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /spring {
proxy_pass http://localhost:9090/spring;
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;
}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
Springboot 시작
업로드한 hello*.war 파일을 아래 명령어로 시작합니다.
ubuntu@goodsaem:~$ java -jar hello-0.0.1-SNAPSHOT.war
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.4)
2021-03-26 23:47:09.084 INFO 819 --- [ main] g.github.io.hello.HelloApplication : Starting HelloApplication using Java 1.8.0_282 on goodsaem with PID 819 (/home/ubuntu/hello-0.0.1-SNAPSHOT.war started by ubuntu in /home/ubuntu)
2021-03-26 23:47:09.095 INFO 819 --- [ main] g.github.io.hello.HelloApplication : No active profile set, falling back to default profiles: default
2021-03-26 23:47:11.586 INFO 819 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 9090 (http)
2021-03-26 23:47:11.617 INFO 819 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2021-03-26 23:47:11.617 INFO 819 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-03-26 23:47:12.505 INFO 819 --- [ main] o.a.c.c.C.[.[localhost].[/spring] : Initializing Spring embedded WebApplicationContext
2021-03-26 23:47:12.505 INFO 819 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3273 ms
2021-03-26 23:47:13.495 INFO 819 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2021-03-26 23:47:13.927 INFO 819 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 9090 (http) with context path '/spring'
2021-03-26 23:47:13.955 INFO 819 --- [ main] g.github.io.hello.HelloApplication : Started HelloApplication in 6.085 seconds (JVM running for 7.154)
springboot 테스트
http://goodsaem.ml/spring/goodsaem/string url 로 접속하여 아래와 같은 화면이 출력되면 nginx + springboot 연동 성공입니다.
안녕하세요 좋은 선생님 goodsaem! 입니다.
'Setup > aws' 카테고리의 다른 글
[AWS 무료 서버구축-15/18] SSL 사이트 점검하기 (0) | 2021.07.25 |
---|---|
[AWS 무료 서버구축-14/18] 무료로 SSL 인증 받기 (0) | 2021.07.25 |
[AWS 무료 서버구축-12/18] Springboot 프로젝트 생성 (0) | 2021.07.25 |
[AWS 무료 서버구축-11/18]Open Jdk 1.8 설치 (0) | 2021.07.25 |
[AWS 무료 서버구축-10/18] Maria DB 유저 생성 및 권한 부여 (0) | 2021.07.25 |
댓글()