Web-Network

[Nginx] mac 로컬 환경에 nginx 설치 실행하기 (local os)

민돌v 2022. 7. 22. 03:57
728x90

 

 

 

 

맥 로컬 환경으로 Nginx 처음부터 설치하고 실행하는 가이드라인

 

  • " Docker 를 사용해서 Nginx 를 웹 서버 로 앞에 두고, Spring 내장 톰캣 (WAS) 에 Nginx 포트를 변경하여 ( 8090 ) 접속해 주세요~ "  라는 온보딩 과제를 받아서 그에 대해 차근차근 공부해나가는 포스팅입니다  

 

 

 

 

1. nginx 설치

  • brew install nginx

 


 

2. nginx 설치 확인

brew services

  • 그냥 실행하면 현재 유저 권한으로 등록/실행된 service 목록 조회
  • sudo를 붙여서 실행하면 root로 등록/실행된 service목록 조회

설치 전

 

설치 후

nginx 가 생성 되었다

 

 

3. nginx 실행 (nginx 명령어 모음)

1) brew services start nginx 

nginx 시작 : brew services start nginx
nginx 재시작 : brew services restart nginx
nginx 중단 : brew services stop nginx
Usage: brew services [subcommand]

Manage background services with macOS' launchctl(1) daemon manager.

If sudo is passed, operate on /Library/LaunchDaemons (started at boot).
Otherwise, operate on ~/Library/LaunchAgents (started at login).

[sudo] brew services [list] (--json):
    List information about all managed services for the current user (or root).

[sudo] brew services info (formula|--all|--json):
    List all managed services for the current user (or root).

[sudo] brew services run (formula|--all):
    Run the service formula without registering to launch at login (or boot).

[sudo] brew services start (formula|--all|--file=):
    Start the service formula immediately and register it to launch at login
(or boot).

[sudo] brew services stop (formula|--all):
    Stop the service formula immediately and unregister it from launching at
login (or boot).

[sudo] brew services kill (formula|--all):
    Stop the service formula immediately but keep it registered to launch at
login (or boot).

[sudo] brew services restart (formula|--all):
    Stop (if necessary) and start the service formula immediately and register
it to launch at login (or boot).

[sudo] brew services cleanup:
    Remove all unused services.

      --file                       Use the service file from this location to
                                   start the service.
      --all                        Run subcommand on all services.
      --json                       Output as JSON.
  -d, --debug                      Display any debugging information.
  -q, --quiet                      Make some output more quiet.
  -v, --verbose                    Make some output more verbose.
  -h, --help                       Show this message.

이외 명령어도 있습니다.

(brew를 사용하지 않더라도, nginx 를 여러 명령어로 다룰 수 있다...! ( https://computer-science-student.tistory.com/393)

 


 

2) localhost:8080으로 접속 (디폴트 포트)

 

 

 


 

 

4. Nginx 설정 하기 

  • Nginx 포트 번호 바꾸기 👉 8080 포트를 8090으로
cd /usr/local/etc/nginx   // ls 하면 nginx.conf 파일 있는거 확인 가능


vi nginx.conf
// 한방도 가능 : vi /usr/local/etc/nginx/nginx.conf

server {
        listen       8080; //여기 포트를 8090 이라 바꾸고 nginx 재시작
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        
        .
        .
        .
        생략
}

 

=> 설정 변경 후, Nginx 재시작 시 변경내역 적용!!

 

 

 

 

 


*참고

https://velog.io/@davelee/mac%EC%97%90-nginx-%EC%84%A4%EC%B9%98%ED%95%98%EA%B8%B0

 

반응형