Nginx - low-hill/Knowledge GitHub Wiki
Nginx port
-
Nginx๋ default port ๋ 80์ด๊ณ , SSL secure connection์ 443port์์ ๋ฐ์ํ๋ค.
-
Uncomplicated firewall์ ๋ณด๋ก ์๋ฒ์ open port ์ ๋ณด ํ์ธํ๊ธฐ
sudo ufw status
-
์ค์ ๊ฐ๋ฅํ application list ํ์ธํ๊ธฐ
sudo ufw app list
- output์ ๋ํ ํด์
Available applications:
Nginx Full // 80(unencrypted traffic) ๋ฐ 443(TLS/SSL) port ์คํ
Nginx HTTP // 80 port๋ง ์คํ
Nginx HTTPS. // 443 port๋ง ์คํ
- 80 port ์คํ ํ ์ํ ํ์ธ
-
sudo ufw allow 'Nginx HTTP'
-
sudo ufw status
-
Nginx configuration ์ค์
sudo vim /etc/nginx/sites-available/example.com
- configuration ํ์ผ ๋ด์ฉ์ ํ์์ ๊ฐ๋ค.
server {
listen 80;
listen [::]:80; // IPv6 addresses
root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ =404;
}
}
- configuration ํ์ผ syntaxํ์ธ ๋ช
๋ น์ด๋ ํ์์ ๊ฐ๋ค.
sudo nginx -t
- configuration ํ์ผ ์์ ์ฌํญ ์ ์ฉ์ ์ํ ํ์ ๋ช
๋ น์ด๋ก ์ฌ๊ธฐ๋ ํ๋ค.
*
sudo systemctl restart nginx
Nginx active ์ํ ํ์ธํ๊ธฐ
-
systemctl status nginx
-
active์ํ์ output์ ํ์์ ๊ฐ๋ค.
-
Active: active (running) since ์๊ฐ ์ ๋ณด
-
inactive ์ํ ์ output
-
inactive (dead)...
-
Nginx ๊ธฐ๋ command
sudo systemctl start nginx
sudo systemctl reload nginx
Nginx error ํ์ธํ๊ธฐ
sudo cat /var/log/nginx/error.log
Maximum Throughput์ ์ํ Nginx ํ๋
-
worker_processes
- default 1, ๋จ์ผ ํ๋ก์ธ์ค maximun์ 1024
- CPU Core ์ ํน์ CPU Core * 2๋ก ์ค์
- CPU Core์ ํ์ธ ๋ฐฉ๋ฒ -> top command ์คํ ํ ์ซ์ 1
- ๋ณ๊ฒฝ๋ worker process ๊ฐฏ์ ํ์ธ ๋ช
๋ น์ด
- ps -aux | grep nginx |grep -v grep
-
worker_rlimit_nofile ์์
- ulimit -n ์์ ๋์ผํ๊ฒ ์ค์ ํ๋๊ฒ์ด ์ข์
-
worker_connections ์์
worker_connections: worker process๋น ๋์์ ์์์๋ก default๊ฐ์ 1024, ์ต๋๋ 65535, os์ file descriptors maximum๊ฐ ๋ฒ์ ์์์ ์ค์ ํ์ ์ฒ๋ผ worker_connections์ ๋ฐ๋ผ ์ต๋ ์ ์์ ์๊ฐ ๊ฒฐ์ ๋๋ค. max_clients = worker_processes * worker_connections
In a reverse proxy situation max_clients = worker_processes * worker_connections/4
events {
# event-models์ epoll์ ์ฌ์ฉ(ํจ์จ๋์)
use epoll;
# ์๋ฒ์ ์ฑ๋ฅ ๋ฐ ๋ฉ๋ชจ๋ฆฌ์ ๋ฐ๋ผ ์ค์
worker_connections 10240;
#์์ฐ๊ฒฐ์ ๋ํ ์๋ฆผ์ ๋ฐ์ ํ ๋ง์ ์ฐ๊ฒฐ์ ํ์ฉ, default๋ off
multi_accept on;
}
- timeout ๋ฑ ์ค์ ์ผ๋ก ์๋ฒ ๋ฆฌ์์ค, CPU, ๋ฉ๋ชจ๋ฆฌ, ์ฐ๊ฒฐ ์ ์ด.
keepalive_timeout 60;
tcp_nodelay on;
client_header_buffer_size 4k;
open_file_cache max=102400 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
client_header_timeout 15;
client_body_timeout 15;
reset_timeout_connection on;
send_timeout 15;
server_tokens off;
client_max_body_size 10m;
- GZIP์์ถ ์ค์
gzip on;
gzip_min_length 1k;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain text/css text/javascript application/json application/javascript;
gzip_vary on;