linux

nginx 설치

javackr 2025. 2. 3. 15:27


##Nginx 

필수 구성 요소 설치
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring

nginx 서명 키를 가져옵니다
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

적절한 키가 포함되어 있는지 확인합니다
gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
출력에는 다음과 같이 전체 지문 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62가 포함되어야 합니다.

최신버전 mainline (nginx-1.24)
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

안전버전 stable (nginx-1.22.1)
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list

과거버전 Legacy (nginx-1.18.0)
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx


최신목록화 시켜기
sudo apt update

설치할수 있는 목록
sudo apt list nginx

설치 => sudo apt install nginx
활성화  => sudo systemctl enable nginx
제거 => sudo apt purge nginx*
재시작 => sudo systemctl restart nginx
버전확인 => nginx -v

Nginx 환경설정 파일 열고 퍼미션 설정
sudo vi /etc/nginx/nginx.conf => 아래와 같이 수정

user www-data;
worker_processes auto;
client_max_body_size 100M; //업로드 사이즈

===최신버전/안전버전 일경우 v1.22.1 이상===
샘플 => /etc/nginx/conf.d/default.conf >> 복사후 호스트설정
복사 => 
sudo cp default.conf linux9.conf
sudo vi linux9.conf => 아래와 같이 편집

===과거버전 일경우 v1.18.0===
샘플 => /etc/nginx/sites-available/default >> 복사후 호스트설정
복사 => 
sudo cp default linux9
sudo vi linux9 => 아래와 같이 편집
활성화=>
sudo ln -s /etc/nginx/sites-available/linux9 /etc/nginx/sites-enabled/
비활성화=>
sudo unlink /etc/nginx/sites-enabled/default

===codeigniter4===
server {
    listen       192.168.0.241:809;
    server_name  192.168.0.241;

    access_log  /home/linux9/logs/access.log;
    error_log /home/linux9/logs/error.log;

    root /home/linux9/html/backend/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    error_page  404              /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\. {
        deny  all;
    }
}
===codeigniter4===


===laravel9===
server {
    listen       192.168.0.241:808;
    server_name  192.168.0.241;

    access_log  /home/linux8/logs/access.log;
    error_log /home/linux8/logs/error.log;

    root /home/linux8/html/backend/public;
    index index.php;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page  404              /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny  all;
    }
}
===laravel9===


===java spring boot===
server {
    listen       192.168.0.241:807;
    server_name  192.168.0.241;

    access_log  /home/linux7/logs/access.log;
    error_log /home/linux7/logs/error.log;

    location / {
        proxy_pass http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
    }
}
===java spring boot===


===node express4===
server {
    listen       192.168.0.241:806;
    server_name  192.168.0.241;

    access_log  /home/linux6/logs/access.log;
    error_log /home/linux6/logs/error.log;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://localhost:3000;
        proxy_redirect off;
    }
}
===node express4===





===기타===
server {
    listen       192.168.0.241:805;
    server_name  192.168.0.241;

    access_log  /home/linux5/logs/access.log;
    error_log /home/linux5/logs/error.log;

    root /home/linux5/html;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    error_page  404              /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\. {
        deny  all;
    }
}
===기타===