beego的Nginx部署

2023-11-21 10:46 更新

Go 是一個獨立的 HTTP 服務器,但是我們有些時候為了 nginx 可以幫我做很多工作,例如訪問日志,cc 攻擊,靜態(tài)服務等,nginx 已經(jīng)做的很成熟了,Go 只要專注于業(yè)務邏輯和功能就好,所以通過 nginx 配置代理就可以實現(xiàn)多應用同時部署,如下就是典型的兩個應用共享 80 端口,通過不同的域名訪問,反向代理到不同的應用。

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;
    }
}
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號