FRAMEWORK/VUE

ubuntu20.04 + nginx + vue 로 환경설정하기

나나나나나나나ㅏ나난ㄴ나ㅏ나나 2021. 7. 21. 19:14
728x90

laravel 프로젝트를 nginx 로 연동한거에 이어 vue 프로젝트도 서버에 올려보자!

 

2020.06.11 - [LINUX] - ubuntu 18.04 + laravel + nginx 로 환경 설정하기

 

ubuntu 18.04 + laravel + nginx 로 환경 설정하기

환경 ubuntu 18.04 php 7.3 nginx 팀장님이 아마존 aws ec2를 이용해서 새로운 ec2를 만들어 보라구 했다! 그래서 아마존 aws ec2에서 새로운 인스턴스를 만들고 환경설정을 했다 기록 안하고있다가 기록하

become-a-developer.tistory.com

 

환경설정

먼저 ubuntu 업데이트 해주기

apt-get upgrade
apt-get update

해준다음 nginx 도 같이 설치해준다

apt-get install nginx

 

설치를 모두 마쳤으면 퍼블릭 ip주소로 들어가서 nginx 사이트가 잘 들어가지는지 확인한다!

이화면이 정상적으로 떠야 한다!

 

서버연동

현재 nginx 기본 페이지로 설정되어있는 nginx 파일을 새로 설정해주어야한다!

/etc/nginx/sites-available/default


##
# 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 {
        listen 80 default_server;
        listen [::]:80 default_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.debian.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;
        root /var/www/<프로젝트명>/dist;

        # 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;
                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:/var/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;
        #}
}

 

여기서 특별하게 변경해야될 부분은 없지만 제일 중요한건 root쪽에 프로젝트 경로로 변경해주어야한다

"root /var/www/<프로젝트명>/dist"

 

그리고 꼭 build된 파일 index.html이 있는 경로일것!!

 

그러고 난뒤 service nginx restart로 nginx 를 껐다키면 설정완료!

728x90