nginx--学习(nignx实现静态资源服务器)
一、nginx实现静态资源服务器
如何实现
- 编写nginx的配置文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
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;
keepalive_timeout 65;
#配置nginx映射下游ssm项目端口
upstream ssm {
server 172.16.253.4:9091 weight=10;
server 172.16.253.4:8081 weight=90;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_pass http://ssm/;
}
}
#配置静态资源服务器
server {
listen 8080;
server_name localhost;
location /{
root /usr/share/nginx/html;
index 1.html;
}
}
}
- 挂数据卷
docker-compose.yml:
version: '3.1'
services:
nginx:
restart: always
image: daocloud.io/library/nginx:latest
container_name: nginx
ports:
- 80:80
- 8080:8080
volumes:
- /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
- /usr/local/docker/nginx/wwwroot/:/usr/share/nginx/html/