요점정리 - 2025-12-17

오늘 공부한 내용
<h5>오늘 공부한 내용:</h5> <ul> <li> <pre> {% set html_content %} nginx 설치 1. 웹서버를 만들어 보자.(nginx) sudo su apt-get install nginx -y netstat -antp | grep nginx 2. 자동실행 systemctl enable/disable nginx 3. 서비스 실행/재실행/중단 systemctl start/restart/stop nginx 4. 기본 인덱스 파일 삭제후 재생성 vi /var/www/html/index.html <html> <head> <title>My home~!</title> </head> <body> Hello? My page! </body> </html> nginx 세팅 server { listen 80 default_server; server_name _; location / { index index.jsp index.html index.htm; proxy_pass http://192.168.186.129:8080; } } WAS 세팅 sudo apt install tomcat10 tomcat10-admin systemctl enable/disable tomcat systemctl start/stop tomcat -------------------------- (참고) 방화벽을 on / off systemctl stop/start ufw -------------------------- 기본 홈디렉토리 : /var/lib/tomcat10/webapps/ROOT 톰캣 홈디렉토리에 직접 접속해 보자(브라우저) http://192.168.186.129:8080/ 6. 기본 코드 실행해 보기 vi /var/lib/tomcat10/webapps/ROOT/test.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Tomcat JSP Test</title> </head> <body> <h2>Tomcat JSP 정상 동작 확인</h2> <p>현재 서버 시간: <%= new java.util.Date() %></p> <p>서버 정보: <%= application.getServerInfo() %></p> <hr> <p style="color:green;">JSP가 정상적으로 실행되고 있습니다.</p> </body> </html> DB 세팅 1. DB 서버 데이터베이스를 설치해보자. sudo su apt-get install mariadb-server systemctl enable mariadb netstat -antp |grep LISTEN 3. db서버에서 원격접속 가능하도록 설정 변경 cd /etc/mysql grep "127.0.0.1" -r ./ vi ./mariadb.conf.d/50-server.cnf --> 127.0.0.1을 찾아 0.0.0.0으로 변경 후 저장 systemctl restart mariadb netstat -antp |grep LISTEN 4. db서버에 접속 가능한 계정을 만들어 보자. -- 사용자 생성 (모든 호스트에서 접속 허용) mysql -u root >CREATE USER 'mydb'@'%' IDENTIFIED BY 'abcd1234'; -- 권한 부여 (모든 DB에 모든 권한, 필요에 따라 조정 가능) >GRANT ALL PRIVILEGES ON *.* TO 'mydb'@'%' WITH GRANT OPTION; -- 권한 즉시 반영 >FLUSH PRIVILEGES; WAS to DB 접속 확인 1. WAS 서버에서 접속을 확인해보자. a. 클라이언트 프로그램 설치 apt install mariadb-client-core -y mysql -u mydb -p -h 92.168.186.130 2. 커넥터 설치 apt install libmariadb-java 파일 생성을 확인해 보자. ls -al /usr/share/java/mariadb-java-client.jar 설치된 커넥터를 톰캣 라이브러리에 추가하자. ln -s /usr/share/java/mariadb-java-client.jar /var/lib/tomcat10/lib/ 3. 톰캣 재시작 * systemctl restart tomcat10 명령어에 worning 발생, 재실행 안됨 systemctl daemon-reload (재구동 성공) DB 생성 drop databases if exists cloud_db; create database cloud_db; use cloud_db; -- 테이블 생성 create table userInfo ( uid int, uname varchar(20), pass varchar(128), profile varchar(200), priority int ); -- 데이터 입력 insert into userInfo (uid, uname, pass, profile, priority)values(0, "admin", "1234", "관리자", 0); insert into userInfo (uid, uname, pass, profile, priority)values(1, "usr1", "abcd", "사용자1", 9); insert into userInfo (uid, uname, pass, profile, priority)values(2, "usr2", "abcd", "사용자2", 9); insert into userInfo (uid, uname, pass, profile, priority)values(3, "usr3", "abcd", "사용자3", 9); // 테이블 속성 확인 desc userInfo; select * from userInfo; SELECT * FROM userInfo WHERE uname="admin" AND pass="abcd"; login.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% String uid = request.getParameter("username"); String pwd = request.getParameter("password"); String DB_URL = "jdbc:mariadb://192.168.186.130:3306/cloud_db"; String DB_USER = "mydb"; String DB_PASSWORD= "abcd1234"; String sel = ""; ResultSet rs = null; Connection conn; Statement stmt; try { Class.forName("org.mariadb.jdbc.Driver"); conn = DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWORD); stmt = conn.createStatement(); //사용자 정보 조회 //출력 예제 >> select * from userInfo where uname=' mydb ' and passwd=password'abcd') sel = "select * from userInfo where uname='" + uid + "' and pass= '" + pwd + "'"; rs = stmt.executeQuery(sel); rs = stmt.executeQuery(sel); if (rs.next()) { response.sendRedirect("index.html"); } else { response.sendRedirect("login.html"); } conn.close(); } catch(Exception e) { out.println(e.getMessage()); } %> login.html <!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <title>Login</title> </head> <body> <h2>로그인</h2> <form action="./login.jsp" method="post"> <div> <label for="username">아이디</label><br> <input type="text" id="username" name="username" required>