Nginx Domain name 변경 및 Kakaomap API 오류 해결

ewillwin·2023년 1월 3일
0

TSMtech Record

목록 보기
23/39

Nginx configure file 변경 및 적용 방법

  • site-available 디렉토리와 site-enabled 디렉토리의 default conf 파일은 soft (symbolic) link를 통해 연동할 수 있는듯
sudo ln -s /etc/nginx/sites-available/proxy-setting1
/etc/nginx/sites-enabled/
  • 최종적으로 site-enabled를 nginx.conf에서 include 해주면 다 synchronize 돼서 그냥 site-available의 default conf 파일만 변경해도 됨
  • 기본적으로 nginx에선 root 권한으로 파일들을 수정해야하는듯 (sudo)
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debiian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html/dist;

        # Add index.php to the list if you are using PHP
        index index.html;

        server_name eco-plans.co.kr;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.html;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}

    #listen [::]:443 ssl ipv6only=on; # managed by Certbot
    #listen 443 ssl; # managed by Certbot
    #ssl_certificate /etc/letsencrypt/live/eco-map.co.kr/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/eco-map.co.kr/privkey.pem; # managed by Certbot
    #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot




    #listen 443 ssl; # managed by Certbot
    #ssl_certificate /etc/letsencrypt/live/eco-plans.co.kr/fullchain.pem; # managed by Certbot
    #ssl_certificate_key /etc/letsencrypt/live/eco-plans.co.kr/privkey.pem; # managed by Certbot
    #include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    #ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


    listen [::]:443 ssl ipv6only=on;
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/eco-plans.co.kr/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/eco-plans.co.kr/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;i
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

server {
    if ($host = eco-plans.co.kr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    if ($host = www.eco-plans.co.kr){
        return 301 https://$host$request_uri;
    } # managed by Certbot

        listen 80 default_server;
        listen [::]:80 default_server;
        server_name eco-plans.co.kr;
    return 404; # managed by Certbot


}

#server {
#    if ($host = eco-plans.co.kr) {
#        return 301 https://$host$request_uri;
#    } # managed by Certbot
#
#
#       server_name eco-plans.co.kr;
#    listen 80;
#    return 404; # managed by Certbot
#
#
#}


#server {
#    if ($host = eco-plans.co.kr) {
#        return 301 https://$host$request_uri;
#    } # managed by Certbot
#    if ($host = www.eco-plans.co.kr){
#       return 301 https://$host$request_uri;
#    } # managed by Certbot
#    server_name www.eco-plans.co.kr; # managed by Certbot
#    return 404; # managed by Certbot
#
#
#
#
#    listen [::]:443 ssl ipv6only=on; # managed by Certbot
#    listen 443 ssl; # managed by Certbot
#    ssl_certificate /etc/letsencrypt/live/eco-plans.co.kr/fullchain.pem; # managed by Certbot
#    ssl_certificate_key /etc/letsencrypt/live/eco-plans.co.kr/privkey.pem; # managed by Certbot
#    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
#    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
#
#}
#server {
#    if ($host = eco-plans.co.kr) {
#        return 301 https://$host$request_uri;
#    } # managed by Certbot
#
#
#
#       server_name eco-plans.co.kr;
#    listen 80;
#    return 404; # managed by Certbot
#
#
#}

#server {
#    if ($host = www.eco-plans.co.kr) {
#        return 301 https://$host$request_uri;
#    } # managed by Certbot
#
#
#
#       listen 80 ;
#       listen [::]:80 ;
#    server_name www.eco-plans.co.kr;
#    return 404; # managed by Certbot
#
#
#}
  • 위 코드는 default config file 내용임
  • server_name에 eco-plans.co.kr 등록해주고, "sudo nginx -t" 명령어 실행 (config file에 오류가 나는지 확인 차)
  • "sudo systemctl restart nginx" 명령어를 통해 nginx 서버 재시작하여 변경된 config file 적용
  • https는 letsencrypt를 이용하여 key를 발급 받아야하는데, certbot 설치하면 "sudo certbot --nginx -d domain.com -d www.domain.com" 이런식으로 certbot을 이용하여 각 domain에 인증서를 발급받을 수 있음 (+ default config file에도 # managed by certbot이라는 주석이 달린 코드가 자동으로 추가됨)

Domain name 변경 후 issue

  • 웹페이지에서 현재위치카카오맵 지도가 표시되지 않음
  • 해결: kakao developer에서 kakao map api를 발급할 때, 사이트도메인을 등록해야함 (서버에서 지도를 띄우는거라 localhost외에 서버의 도메인네임을 등록해야함)
profile
Software Engineer @ LG Electronics

0개의 댓글