---
# System prepended metadata

title: nginx 筆記
tags: [nginx, cloud]

---

# nginx 筆記

https://serverfault.com/questions/1042526/open-run-nginx-pid-failed-13-permission-denied

## 錯誤紀錄1
`nginx -t`
:::danger
2024/12/14 13:42:25 [emerg] 40557#40557: open() "/run/nginx.pid" failed (13: Permission denied)
:::
解決
[ref](https://serverfault.com/questions/1042526/open-run-nginx-pid-failed-13-permission-denied)
```
sudo mkdir -p /etc/systemd/system/nginx.service.d
sudo vim /etc/systemd/system/nginx.service.d/override.conf
sudo systemctl daemon-reload
sudo systemctl restart nginx
```
## 錯誤紀錄2
在oracle instance 上，使用任何port都要添加Security Rule，卡了好久QAQ。
:::success
在添加新的安全規則後，錯誤訊息終於改變了
:::

## 錯誤紀錄3
:::danger
瀏覽器顯示
(Reason: CORS request did not succeed). Status code: (null)
:::
我嘗試安裝了 CORS，但安裝沒有解決問題。
我查看了設定檔 `sudo vim /etc/nginx/conf.d/default.conf`
```
    location /service5000/ {
            proxy_pass http://127.0.0.1:5000/;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

```
我其實把東西放到`/service5000`，而我之前一直在嘗試讀取`"http://141.147.150.224:5000/api/data`，之後讀取`"http://141.147.150.224/service5000/api/data"`才正常。

### 錯誤紀錄4
app.py
```
伺服器設定
'/api/data'
客戶端設定
"http://141.147.150.224/service5000/api/data"
nginx設定
'/service5000/'
```
這樣是可以的，但是當我嘗試
```
伺服器設定
`/data`
客戶端設定
"http://141.147.150.224/api/data"
nginx設定
'/api/'
```
卻失敗了... ?
















