티스토리 뷰
nginx 삭제
sudo apt-get purge nginx nginx-common nginx-full
nginx 설치
sudo apt-get install nginx
nginx 시작
nginx
nginx 재시작
sudo service nginx restart
또는
nginx 설정파일 다시 불러오기
nginx -s reload
무지성 Nginx니까 백업폴더를 만드는 거는 생략
cd /etc
cd /nginx
cd /sites-available
들어가면 default 파일이 있음. 여기서 nginx 설정

sudo vi default
깜빡하고 sudo 안 치고 들어가면 수정이 안되니까 주의
http{
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;
# 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;
}
# 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;
#}
}
}
http > server > location
http 안에 server, server안에 location 이 있음
server {
listen 80;
}
80번 포트로 들어오는 거 Nginx를 거치게 됨.
front nginx
location / {
#proxy_pass http://localhost:81;
root /home/ubuntu/gitclone한폴더/build;
index index.html index.htm;
try_files $uri /index.html;
}
root를 프론트 빌드 폴더 경로로 바꿔줌.
프론트 빌드한 다음에 pwd 찍어서 나오는 경로 복붙해줌.
/ 경로로 오는 요청은 이곳으로 빠짐.
그리고
esc 누르고
:wq +Enter
빠져나옴.
default 의 내용을 수정한 다음 잘 수정 한 건지 확인
sudo nginx -t

설정 바꾸고
nginx 재시작
sudo service nginx restart
또는
nginx 설정파일 다시 불러오기
nginx -s reload
back nginx
http {
. . .
upstream 마음에 드는 이름{
server IP:PORT
}
. . .
}
http 안에,
upstream 변수 설정.
server 설정에서 Nginx가 받은 요청을 어떤 서버로 보내줄 것인가?
ip와 port를 지정해주면 됨.
++여러개를 지정해줄 수도 있음. 로드밸런싱??
예)
upstream backend{
server localhost:3002;
}
location /api/ {
#proxy_hide_header Access-Control-Allow-Origin;
#add_header 'Access-Control-Allow-Origin' '*';
proxy_pass http://backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_connect_timeout 3000;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
send_timeout 3000;
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
}
location /api/
=> /api/ 로 들어오는 부분 관리.
예를 들어서
ehdcjf.com 으로 들어오는 요청은 위에서 설정한 front로 빠지고.
ehdcjf.com/api로 들어오는 요청은 여기로 빠짐.
proxy_pass
proxy_pass 부분에 upstream에서 정해줬던 이름 사용.
proxy_pass http://backend;
딱히 upstream으로 뭐 할게 있는게 아니면 그냥 여기에 ip랑 port 박아도 됨.
proxy_pass http://localhost:3002;
nginx 에러 모음
Nginx: 413 - Request Entity Too Large Error
=> 요청 크기가 너무 커서 그렇다. 이 사이즈를 늘려주면됨.
server {
...
client_max_body_size 0;
...
}
client_max_body_size 5M; 이런식으로 지정해줌. 0이면 무제한
Nginx: 504 - Gateway Time-out Error
=> 제한 시간을 늘려줘야됨. 숫자는 초단위.
location{
...
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
....
}
- Total
- Today
- Yesterday
- 서버개발
- 면접비
- create databases;
- 서버점검
- 개발자면접
- DB 생성
- MySQL
- KMP
- 최소공통조상
- 투포인터
- 다이나밍프로그래밍
- 동적프로그래밍
- MOD
- create db
- 면접질문
- 그래프
- BFS
- 다이나믹프로그래밍
- 투포인터 연습
- 로드나인
- node.js
- 은둔청년체험
- 롱베케이션
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
