반응형
우분투에서 NGINX의 최신 버전(안정 버전)을 설치하는 방법
nginx : High performance web server
Ubuntu : http://nginx.org/en/linux_packages.html#Ubuntu
테스트 환경
- 운영체제 버전 정보
$ lsb_release -d
Description: Ubuntu 22.04.2 LTS
NGINX 설치
필수 구성 요소 설치
sudo apt-get update
sudo apt-get install -y curl gnupg2 ca-certificates lsb-release
ubuntu-keyring, apt-transport-https 패키지 설치
sudo apt-get install -y ubuntu-keyring apt-transport-https
nginx.list 파일 생성
NGINX 공식 저장소에서 서명 키 가져오기
curl -s https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
다운로드한 키가 올바른지 확인
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
$ gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
uid nginx signing key <signing-key@nginx.com>
NGINX 저장소 추가(안정 버전)
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
$ 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
deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] http://nginx.org/packages/ubuntu jammy nginx
APT 저장소 업데이트
sudo apt-get update
728x90
NGINX 패키지 설치
sudo apt-get install -y nginx
$ sudo apt-get install -y nginx
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
nginx
...
Preparing to unpack .../nginx_1.24.0-1~jammy_amd64.deb ...
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* https://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* https://nginx.com/products/
----------------------------------------------------------------------
Unpacking nginx (1.24.0-1~jammy) ...
Setting up nginx (1.24.0-1~jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /lib/systemd/system/nginx.service.
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning processor microcode...
Scanning linux images...
Running kernel seems to be up-to-date.
The processor microcode seems to be up-to-date.
설치된 NGINX 버전 정보 확인
nginx -v
$ nginx -v
nginx version: nginx/1.22.1
NGINX 서비스 시작 및 활성화
sudo systemctl --now enable nginx
NGINX 서비스 상태 확인
sudo systemctl status nginx
NGINX 버전 정보 숨기기
nginx.conf 편집
vim /etc/nginx/nginx.conf
더보기
---
cat /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
---
http {
...
server_tokens off;
...
server {
listen 80;
server_name _;
...
location /nginx_status {
# Nginx status 페이지 설정
stub_status;
access_log off;
allow 127.0.0.1;
allow 192.168.56.0/24;
deny all;
}
}
}
NGINX 구문 검사
nginx -t
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
NGINX 서비스 재시작
sudo systemctl restart nginx
NGINX 상태 페이지 확인
curl http://localhost/nginx_status
Active connections: 1
server accepts handled requests
2 2 2
Reading: 0 Writing: 1 Waiting: 0
참고URL
- NGINX Documentation : Ubuntu
728x90
반응형
'리눅스' 카테고리의 다른 글
CentOS7에서 EDAC(Error Detection And Correction) 로그 확인하는 방법 (0) | 2023.04.11 |
---|---|
우분투에서 PHP-FPM 최신(php-fpm 8.2) 버전 설치하기 (0) | 2023.04.10 |
우분투에서 부팅 모드를 변경하는 방법 (0) | 2023.04.07 |
포워드 프록시와 리버스 프록시의 차이점과 역할 (0) | 2023.04.07 |
[리눅스] 리눅스에서 시간 변환하는 명령어 (0) | 2023.04.06 |