ฉันมีแอปพลิเคชัน NodeJs ที่ทำงานบน localhost:8000 และฉันกำลังใช้ Nginx เป็นพร็อกซีเซิร์ฟเวอร์ นี่เป็นแอปพลิเคชันเดียวที่ทำงานบน Nodejs ในขณะที่แอปพลิเคชันอื่นใช้ PHP
ฉันกำลังพยายามตั้งค่าพร็อกซีใน Nginx เพื่อเปลี่ยนเส้นทางคำขอทั้งหมดจาก "http://localhost/NodeApp/" เป็น " http://localhost:8000/" Nginx ควรดึงข้อมูลเฉพาะไฟล์ css/js/images จาก nodeapp นี้โดยตรง คำขออื่นๆ ทั้งหมดจะถูกส่งไปยังเซิร์ฟเวอร์ Apache การกำหนดค่า Nginx เป็นเช่นนี้ -
#Need to modify this code to fetch static files for NodeApp only!
location ~ ^/(uploads/|vendor/|images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
root /var/www/NodeApp/public;
access_log off;
}
location /NodeApp/ {
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;
proxy_pass http://localhost:8000/;
}
การกำหนดค่าข้างต้น Nginx จะทำลายแอปพลิเคชันอื่น ๆ เนื่องจากค้นหาไฟล์คงที่ในโฟลเดอร์สาธารณะ NodeApp ฉันจะแก้ไขการกำหนดค่าด้านบนให้ทำงานเฉพาะกับ "localhost/NodeApp/" ได้อย่างไร
ฉันลองกำหนดค่าด้านล่าง แต่นั่นทำให้โฟลเดอร์คงที่ NodeApp พังมีโฟลเดอร์ย่อย - /public/js/bootstrap/ /public/js/datepicker/ /public/css/bootstrap/ /public/css/datepicker/ /public/uploads/pdf / /สาธารณะ/รูปภาพ/
location /NodeApp/ {
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;
proxy_pass http://OneDesktop/;
alias /var/www/NodeApp/public/;
}
คำแนะนำใด ๆ? ฉันลองมาหลายอย่างแล้ว แต่ก็ไม่มีโชค!
ขอบคุณ!