Smilegate-WWW / wow-welcome-webtoon

🚀 Smilegate Online Server Dev Camp 1st : Team "WWW" / SpringBoot, JPA, Mysql, Redis, Nginx, React
3 stars 1 forks source link

Nginx proxy server #29

Open ji-water opened 4 years ago

ji-water commented 4 years ago

(20.03.01) 정규표현식으로 중첩 표현 가능한 location들은 합쳤습니다 (20.03.01 20:31) 오타 수정했습니다.. (20.03.02 04:33) /users url 통과 안되는 것 수정했습니다

server {
        #port
        listen 1234;

        ####auth server
        location = /users {
                proxy_pass http://127.0.0.1:8080/users;
        }
        location = /users/token{
                proxy_pass http://127.0.0.1:8080/users/token;
        }
        location ~* /users/(?<user_idx>[0-9]+)/token{
                proxy_pass http://127.0.0.1:8080/users/${user_idx}/token;
        }
        location ~* /users/(?<user_idx>[0-9]+){
                proxy_pass http://127.0.0.1:8080/users/${user_idx};
        }

        ####file server
        location ~* /myTitleDetail(?<q>.*){
                proxy_pass http://127.0.0.1:8081/myTitleDetail${q};
        }
        location ~* ^/myTitleList(.*) {
                proxy_pass http://127.0.0.1:8081/myTitleList$1$is_args$args;
        }
        location ~* /myArticleDetail/(?<webtoon_idx>[0-9]+)(.*) {
                proxy_pass http://127.0.0.1:8081/myArticleDetail/${webtoon_idx}$2;
        }
        location ~* /myArticleList/(?<idx>[0-9]+)(.*) {
                proxy_pass http://127.0.0.1:8081/myArticleList/${idx}$2$is_args$args;
        }
        location ~* ^/webtoonlist(.*) {
                proxy_pass http://127.0.0.1:8081/webtoonlist$1$is_args$args;
        }
        location ~* /episode/(?<webtoon_idx>[0-9]+) {
                proxy_pass http://127.0.0.1:8081/episode/${webtoon_idx};
        }
        location ~* /mydetail(.*) {
                proxy_pass http://127.0.0.1:8081/mydetail$1;
        }
        location ~* /detail/(?<webtoon_idx>[0-9]+)(.*){
                proxy_pass http://127.0.0.1:8081/detail/${webtoon_idx}$2;
        }

        ####platform server
        location ~* /comments/(?<ep_idx>[0-9]+)(?<q>.*) {
                proxy_pass http://127.0.0.1:8082/comments/${ep_idx}${q};
        }
        location ~* /episodes/(?<ep_idx>[0-9]+)/comments(.*) {
                proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/comments$2$is_args$args;
        }
        location ~* /episodes/(?<ep_idx>[0-9]+)/rating {
                proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/rating;
        }
        location ~* /users/comments(.*) {
                proxy_pass http://127.0.0.1:8082/users/comments$1$is_args$args;
        }

        error_page 404 /404.html;
}
참고 [location 우선순위] ![image](https://user-images.githubusercontent.com/47727109/75609974-8f6cb980-5b50-11ea-9189-f4ec0cd8f0fa.png) ![image](https://user-images.githubusercontent.com/47727109/74651723-c98ca180-51c7-11ea-9110-f91937967910.png) [정규표현식] https://ko.wikipedia.org/wiki/%EC%A0%95%EA%B7%9C_%ED%91%9C%ED%98%84%EC%8B%9D
ji-water commented 4 years ago
수정 전 ``` server { #port listen 1234; ####auth server location /users { proxy_pass http://127.0.0.1:8080/users; } location /users/token{ proxy_pass http://127.0.0.1:8080/users/token; } location ~* /users/(?[0-9]+)/token{ proxy_pass http://127.0.0.1:8080/users/${user_idx}/token; } location ~* /users/(?[0-9]+){ proxy_pass http://127.0.0.1:8080/users/${user_idx}; } ####file server location /myTitleDetail{ proxy_pass http://127.0.0.1:8081/myTitleDetail; } location ~* ^/myTitleList(.*) { proxy_pass http://127.0.0.1:8081/myTitleList$1$is_args$args; } location ~* /myArticleList/(?[0-9]+) { proxy_pass http://127.0.0.1:8081/myArticleList/${idx}; } location ~* /myTitleDetail/(?[0-9]+) { proxy_pass http://127.0.0.1:8081/myTitleDetail/${idx}; } location ~* /myArticleDetail/(?[0-9]+)/(?[0-9]+) { proxy_pass http://127.0.0.1:8081/myArticleDetail/${webtoon_idx}/${no}; } location ~* /myArticleList/(?[0-9]+)/(?[0-9]+) { proxy_pass http://127.0.0.1:8081/myArticleList/${webtoon_idx}/${no}; } ## 수정 ↓ location ~* /myArticleList/(?[0-9]+)(.*) { proxy_pass http://127.0.0.1:8081/myArticleList/${idx}$1$is_args$args; } ## 추가 2개 location ~* ^/webtoonlist(.*) { proxy_pass http://127.0.0.1:8081/webtoonlist$1$is_args$args; } location ~* /episode/(?[0-9]+) { proxy_pass http://127.0.0.1:8081/episode/${webtoon_idx}; } ####platform server location ~* /comments/(?[0-9]+) { proxy_pass http://127.0.0.1:8082/comments/${ep_idx}; } location ~* /episodes/(?[0-9]+)/comments { proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/comments; } location ~* ^/episodes/(?[0-9]+)/comments(.*) { proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/comments$1$is_args$args; } location ~* /episodes/(?[0-9]+)/comments/(?[0~9]+) { proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/comments/${cmt_idx}; } location ~* /episodes/(?[0-9]+)/comments/best { proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/comments/best; } location ~* /comments/(?[0-9]+)/like { proxy_pass http://127.0.0.1:8082/comments/${ep_idx}/like; } location ~* /comments/(?[0-9]+)/dislike { proxy_pass http://127.0.0.1:8082/comments/${ep_idx}/dislike; } location ~* /episodes/(?[0-9]+)/rating { proxy_pass http://127.0.0.1:8082/episodes/${ep_idx}/rating; } location ~* ^/users/comments(.*) { proxy_pass http://127.0.0.1:8082/users/comments$1$is_args$args; } error_page 404 /404.html; } ```