W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Go 是一個獨立的 HTTP 服務(wù)器,但是我們有些時候為了 nginx 可以幫我做很多工作,例如訪問日志,cc 攻擊,靜態(tài)服務(wù)等,nginx 已經(jīng)做的很成熟了,Go 只要專注于業(yè)務(wù)邏輯和功能就好,所以通過 nginx 配置代理就可以實現(xiàn)多應(yīng)用同時部署,如下就是典型的兩個應(yīng)用共享 80 端口,通過不同的域名訪問,反向代理到不同的應(yīng)用。
server {
listen 80;
server_name .a.com;
charset utf-8;
access_log /home/a.com.access.log;
location /(css|js|fonts|img)/ {
access_log off;
expires 1d;
root "/path/to/app_a/static";
try_files $uri @backend;
}
location / {
try_files /_not_exists_ @backend;
}
location @backend {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8080;
}
}
server {
listen 80;
server_name .b.com;
charset utf-8;
access_log /home/b.com.access.log main;
location /(css|js|fonts|img)/ {
access_log off;
expires 1d;
root "/path/to/app_b/static";
try_files $uri @backend;
}
location / {
try_files /_not_exists_ @backend;
}
location @backend {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:8081;
}
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: