---
# System prepended metadata

title: Nginx 小筆記

---

Nginx 小筆記
===

## 安裝

```
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx -y

systemctl enable nginx.service && systemctl start nginx.service
```
---
```
version: '3.3'

services:
  nginx:
    container_name: nginx
    restart: always
    image: nginx:1.19.10
    ports:
        - 80:80
    volumes:
        - ./nginx/nginx.conf:/etc/nginx/nginx.conf
        - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    
  
```

## conf 設定
```
server {
    listen 		8090;
    server_name SERVER_IP;

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	
    # 
	location / {
		root		C:/nginx/html/admin;
		index		index.html index.htm index.php;
	}
	
    # 反向代理
	location ~ ^/api {
        proxy_pass         https://127.0.0.1:50001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
	
}
```
