像這樣
www.example.com
blog.example.com
但是不同的應(yīng)用,例如www.example.com是靜態(tài)頁(yè)面,而blog.example.com是nodejs應(yīng)用程式
能做到嗎?具體怎麼配置呢?
靜態(tài)頁(yè)面設(shè)定root,應(yīng)用程式設(shè)定反向代理即可
server {
listen 80;
server_name blog.example.com ;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
}
server {
listen 80;
server_name www.example.com;
location / {
root E:/Example/public;
}
}
配置虛擬主機(jī)咯
貼一下偽代碼供參考吧
設(shè)定檔 nginx.conf 的 server段最後處加入
include vhost/*.conf;
建立vhost目錄
vhost目錄下建立檔案 例如 www.example.com.conf,blog.example.com.conf
然後做大致如下設(shè)定
server
{
listen 80;
server_name www.example.com;
index index.php index.html index.htm ;
root /var/www/www.example.com;
if ( $fastcgi_script_name ~ \..*\/.*php ) {
return 403;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
當(dāng)然,nodejs不依賴(lài)ng,ng指定nodejs應(yīng)用程式資料夾,網(wǎng)域存取只觸發(fā)初始化,其他的通訊跟解釋交回給node服務(wù)