---
# System prepended metadata

title: Nginx個人常用配置

---

# Nginx個人常用配置

## 前端Vue聊天室 & 後端Node.js SocketIO
``` nano=
server {
    server_name vue.jimmyy512.com;
    location ~* \.io {
        proxy_pass http://127.0.0.1:3003;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header X-Real-IP $remote_addr;                       # 加入 X-Real-IP Header
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   # 加入 X-Forwarded-For Header
        proxy_redirect off;
    }

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;                       # 加入 X-Real-IP Header
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   # 加入 X-Forwarded-For Header
        root /home/jimmyy5121/vue_chat_server/client/dist;
        index index.html index.htm;
    }
}
```

## 前端Vue + 後端/api 訪問API
``` nano=
server {
    server_name vue3-todolist.jimmyy512.com;
    location /api/ {
        proxy_pass http://localhost:3087/;
    }
    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;                       # ~J| ~E X-Real-IP Header
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   # ~J| ~E X-Forwarded-For Header
        root /root/Vue3-TS-TodoList/dist;
        index index.html index.htm;
    }
}
```