안녕하세요 상훈입니다.

 

해당 프로젝트는 Vue.js, React.js 등 SPA 의 공통적인 요소이기 때문에,
SPA 프로젝트를 빌드하여 같은 오류가 난다면 마찬가지로 진행해주셔도 무방합니다.

 

React.js 프로젝트를 build -> nginx server 에 배포하였습니다.

그런데, nginx 서버에서 index.html 파일을 정상적으로 불러왔는데, 새로고침했을 때 404에러가 떠버렸습니다.

왜 404 Not Found 가 뜨냐고!

 

 

기본적인 빌드 환경은 다음과 같습니다.

/var/www/html/build/index.html 

그렇다. build 라는 디렉터리가 또 껴있는 것이다. 

그래서 error.log 를 줄기차게 테스트해보면서 확인해봤다.

이렇게 경로를 읽어오고 있었던 것.

이제 에러를 확인했으니, 고쳐야지..

*참고 : error.log 는 /var/log/niginx/error.log  에 있다.

일단 Ubuntu, Nginx 를 이용하는 입장에서만 서술하도록 하겠습니다.

 /etc/nginx/sites-enabled/default  를 수정하면 되는데, 아래 이미지처럼 수정하면 된다.

server {
	root /var/www/html/build/;
    
    index index.html
    
    #... 이하생략
    
    location / {
    	#이부분을 수정해주시면 됩니다.
    	try_files $uri $uri/ /index.html;
    }   
}

저는 저 try_files 부분에서 index.html 로만 작성이 되어져 있었기에
build/index.html 이 아닌 buildindex.html 로 uri 호출이 되었더라구요.

수정내역

 

그래서 위와 같이 수정해주고, (sudo nano default) 저장. 그리고 서버 재시작

 sudo service nginx restart 

 

그리고.....

감덩...👍

새로고침 시 해당 페이지가 다시 호출되어 화면에 렌더링 되는 것을 볼 수 있습니다.

 

이게 뭐라고 계속 이렇게 끙끙 앓았다니 속상하네요.

반응형

안녕하세요 상훈입니다. Linux Ubuntu 에서 ssh 용 Key를 generate 하는 방법에 대해 포스팅 하겠습니다.

 

서버에서 ssh-keygen 이라는 명령어를 쳐주세요

ssh-keygen

그러면 아래와 같이 (윈도우로 예시를 들었습니다만 원래는 linux-server 에서 사용합니다.) 
특정 경로에 해당하는 id_rsa 가 생성되었습니다.

그리고 비밀번호를 입력하면되는데, 만약 입력하지 않을 것이면 바로 엔터로 넘어가주시면 됩니다.

 

그러면 .ssh 라는 폴더 안에 아래와 같이 생성되셨을 겁니다.

리눅스의 경로는 ~/.ssh 입니다.

리눅스-우분투의 경우 기본 경로는 ~/.ssh 이기 때문에 cd ~/.ssh 하면 확인 가능합니다.

id_rsa 파일 중 확장자 .pub 를 가지고 있는 파일이 public key
그리고 확장자가 없는 것이 private key 입니다!

이제 자유롭게 사용하시면 됩니다!

 

이상입니다.

반응형

 

사용환경 :  Ubunut 20.0.4 LTS, Apache2.x, Node.js, Javascript

 

Apache설정 변경

# /etc/apache2/sites-available/000-default.conf  내용 추가

<VirtualHost  *:80>
ServerName example.com

           ProxyRequests Off
           ProxyPreserveHost On
           ProxyVia Full
           <Proxy *>
              Require all granted
           </Proxy>

           <Location /nodejs>
              ProxyPass http://localhost:3000
              ProxyPassReverse http://localhost:3000
           </Location>

            <Directory "/var/www/example.com/html">
                    AllowOverride All
            </Directory>
</VirtualHost>

3000포트로 허용함을 설정

$ sudo service apache2 restart

아파치 서버 재구동 

 

# /var/www/html/nodejs/hello.js

var http = require('http');
http.createServer(function (request, response) {
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World! Node.js is working correctly.\n');
}).listen(3000);
console.log('Server running at http://127.0.0.1:3000/');
console.log('It is running now...');

마찬가지로 3000포트 연결 설정

 

hello.js 파일 실행

$ node /var/www/html/nodejs/hello.js 

console.log 했던 내용 출력

 

 

http://example.com:8080/node.js/
접속

접속완료

 

 

일단 서버 내에서 8080포트로 접속하여 3000포트의 Websocket communication 로그 출력이 완료되었다.

 

 

 

 

Apache + Node.js + socket.io

코드 이그나이터에서 웹소켓을 돌리는데 드디어 성공! 꽤나 뿌듯하다. 스택 오버플로우와 국내 블로그의 도움을 많이 받았다. 순서대로 오늘 한 일에 대해서 나열해보자면 1. 공유기 포트포워딩

blog.rgbplace.com

 

Set Up a Node.js App for a Website With Apache on Ubuntu 16.04

This tutorial will explain how to set up a Cloud Server running Ubuntu 16.04 so that Node.js scripts run as a service, and configure the Apache server to make the script accessible from the web.

www.ionos.com

 

Behind a reverse proxy | Socket.IO

You will find below the configuration needed for deploying a Socket.IO server behind a reverse-proxy solution, such as:

socket.io

 

반응형
반응형

+ Recent posts