Skip to content

Instantly share code, notes, and snippets.

@sigridjineth
Forked from ksundong/README.md
Created April 28, 2020 20:56
Show Gist options
  • Select an option

  • Save sigridjineth/39967db32a3e91e7b82176316255f17c to your computer and use it in GitHub Desktop.

Select an option

Save sigridjineth/39967db32a3e91e7b82176316255f17c to your computer and use it in GitHub Desktop.
NginX spring reverse proxy설정 및 프론트 산출물 저장 경로 알아내기

NginX Reverse Proxy 설정

  • 설정 파일 수정

    sudo vi /etc/nginx/sites-available/default

            # Add index.php to the list if you are using PHP
            index index.html index.htm index.nginx-debian.html;
    
            server_name _;
    
            location / {
                    # First attempt to serve request as file, then
                    # as directory, then fall back to displaying a 404.
                    try_files $uri $uri/ =404;
            }
    
            location /api/ {
                    rewrite ^/api(/.*)$ $1 break; # url에서 api 뒤에 있는 URL을 전부 그대로 사용.
                    # ip/api/blahblah로 들어온 요청은 ip/blahblah로 Spring에 전달됩니다.
                    proxy_pass http://localhost:8080;
            }
    

    해당 내용으로 수정하고

    sudo service nginx restart 실행

    spring에 보내는 요청이 /api를 통해서 80포트에서 정상적으로 전달되는지 확인.

이렇게 설정하면 api라고 경로를 지정해야 8080포트로 요청이 전달됩니다.

물론 api는 Spring에서 지정해주지 않아도, rewrite로 경로가 지정됩니다.

NginX 프론트 산출물 저장하는 경로

/var/www/html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment