我使用 NGINX 在我的 vps 上托管了一個網站,我的后端(在 Node.js 中)位于“/root/backend/MyApp”目錄中。我的前端(在 React.js 中)由“/var/www/app/client”提供,其中包含我的構建檔案,包括 index.html。我通過“/api/upload/profileimage”端點存盤用戶的個人資料影像,并使用“Multer”將影像上傳到“/root/backend/MyApp/uploads/profileImages”目錄中。如何配置 nginx 以便我可以通過前端的 url 提供這些上傳的影像?現在我的服務器配置如下:
server {
server_name {my domain name};
location / {
root /var/www/app/client;
index index.html index.htm;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://185.201.8.18:8800;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ /index.html;
}
}
uj5u.com熱心網友回復:
嘗試這個:
server {
server_name {my domain name};
location / {
root /var/www/app/client;
index index.html index.htm;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://185.201.8.18:8800;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ /index.html;
}
location /profileimages/ {
autoindex on;
alias /root/backend/MyApp/uploads/profileImages/;
}
}
您應該能夠訪問影像:yourwebsite.com/profileimages/
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/507694.html
標籤:节点.js 反应 nginx 网络部署 nginx-反向代理
上一篇:Nginx301使用通配符重定向
下一篇:Nginx占用整個域而不是子域