我真的很困惑它是否可能?請幫助我,我有Node.js應用程序,說node_app,運行在X端口,PHP應用程序,比如my_app,運行在Apache的默認80端口。我只有一個域名。我的問題是,如果用戶點擊domain.com/my_app,它應該在80端口運行PHP應用程序。如果用戶點擊domain.com/node_app,它應該在X端口運行節點應用程序。另一個重要的限制是最終用戶不應在URL欄中看到任何端口號。在同一臺機器上運行Node.js應用程序和PHP
1
A
回答
1
您可以將Node.JS和PHP安裝在同一臺主機上,使用Nginx作爲代理例程。
每爲例,與Nginx的,你可以創建兩個virtualhosts:使用PHP(FPM與否)誰指向exemple.tld
- 默認的虛擬主機。 TLD
首先VH是會是這樣的(用PHP-FPM):
server {
listen 80; ## listen ipv4 port 80
root /www;
index index.php index.html index.htm;
# Make site accessible from exemple.tld
server_name exemple.tld;
location/{
try_files $uri $uri/ /index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 and using HHVM or PHP
#
location ~ \.(hh|php)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
第二VH用的NodeJS:
server {
listen 80;
server_name node.exemple.tld;
location/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
access_log off;
# Assuming that NodeJS listen to port 8888, change if it is listening to another port!
proxy_pass http://127.0.0.1:8888/;
proxy_redirect off;
# Socket.IO Support if needed uncomment
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
}
# IF YOU NEED TO PROXY A SOCKET ON A SPECIFIC DIRECTORY
location /socket/ {
# Assuming that the socket is listening the port 9090
proxy_pass http://127.0.0.1:9090;
}
}
正如你所看到的,這是可能的,而且很容易做到!
+0
我不確定,它是否會起作用,因爲我從來沒有使用過Nginx,但是很明顯,任何人都可以通過閱讀本文來理解。對不起,我沒有太多的名譽投票給你。 –
+0
沒問題,這真是一種享受@VijayAnand – GotchaRob
相關問題
- 1. PHP和node.js可以在同一臺服務器上運行
- 2. 如何在同一臺機器上同時運行JSP和PHP
- 3. 在同一臺機器上爲不同的應用程序運行多個jvms
- 4. 在另一臺機器上運行Windows 8.1應用程序
- 5. 如何在另一臺機器上運行web應用程序?
- 6. 如何在同一臺機器上運行ASP.NET和PHP?
- 7. 運行在同一臺機器上的多個Java程序
- 8. 當多個Java程序在同一臺機器上運行時
- 9. 如何在同一臺主機上運行Angular Client應用程序和節點服務器應用程序
- 10. JBoss 7:獨立或域:在一臺機器上運行多個應用程序(同一個應用程序)
- 11. 在同一臺機器上的不同應用程序上運行capistrano v2和v3
- 12. 在主機服務器上運行控制檯應用程序
- 13. 在同一臺機器上同時運行Windows 7和Server 2012
- 14. 在同一臺機器上同時運行python 2.6和3.1
- 15. Node.js 4和Node 5在運行OS X「EL Capitan」的同一臺機器上
- 16. 在一臺機器上運行的Android程序沒有在另一臺機器上運行
- 17. 在Azure上運行Node.js應用程序
- 18. 在兩臺顯示器上運行不同的應用程序
- 19. 在同一臺服務器上運行PHP 5.4和PHP 7
- 20. HTTP POST請求到在同一臺計算機上運行的應用程序?
- 21. MySQL Server 5.7和WAMPServer在同一臺機器上不能運行
- 22. 在同一臺機器上運行Python 3.2和2.7
- 23. 在同一臺Windows機器上運行庫存python和Anaconda
- 24. 如何在同一臺機器上運行ASP.NET MVC 1和2?
- 25. 在同一臺機器上運行Matlab MCR和MATLAB
- 26. C#應用程序不在不同的機器上運行
- 27. 爲什麼此PHP代碼在一臺機器上運行並在另一臺機器上運行失敗?
- 28. 在同一臺機器上運行的用戶會話和兩個CakePHP應用程序
- 29. Java:如何使jvm和http monitor在同一臺機器上運行在外部的應用程序安全?
- 30. 在另一臺機器上運行我的應用程序時出錯
您可以通過apache設置代理通過特定路徑到達您計算機上另一個端口(如節點服務器)的請求。但是,這可能是[服務器故障](http://serverfault.com/)的一些原因,因爲它更多的與網絡和服務器管理有關,而不是程序設計。 –