Nginx

주소를 치면 가야할 길을 안내해주는 것

by 내가 사는 세상

Advanced Load Balancer, Web Server, & Reverse Proxy



nginx


시작점 : 컨테이너 속 /etc/nginx/nginx.conf




Nginx 컨테이너 내부구조



/etc/nginx

- nginx.conf



// 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;

}


아래 폴더 경로에 있는 어쩌구.conf 파일들의 내용을 포함시킨다. nginx.conf 파일이 엄청 길어지는 것이다. 한번 가서 찾아보자.



/etc/nginx/conf.d/

- default.conf



// default.conf

server {

listen 80;

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;

#}

}


주소창에 ip(ex. http://123.456.789.123/)를 치면 보여지게 되는 html 파일의 위치를 알려준다. 지금은 index.html 파일을 보여준다고 설정되어 있다. 살펴보자.




/usr/share/nginx/html

- 50x.html

- index.html


// index.html

<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

html { color-scheme: light dark; }

body { width: 35em; margin: 0 auto;

font-family: Tahoma, Verdana, Arial, sans-serif; }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>

<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>

</body>

</html>



관련 이슈 경험


로컬의 nginx.conf 파일을 연결시키면 nginx에서 제공하는 기본 페이지 나타남

docker-compose.yml

volumes:
- ../config/nginx/nginx.conf:/etc/nginx/nginx.conf

- ../config/nginx/default.conf:/etc/nginx/nginx.conf

keyword