beeblog icon indicating copy to clipboard operation
beeblog copied to clipboard

如何部署此应用到远程服务器呢?

Open Xavier-Zeng opened this issue 5 years ago • 6 comments

大佬您好,我学习了你写的这个博客应用,想把它部署在远程服务器。我参考beego的部署教程(https://beego.me/docs/deploy/nginx.md),使用nginx进行部署。nginx配置如下:

server {
    listen       80;
    server_name  localhost;

    charset utf-8;
    access_log  /home/a.com.access.log;

    location /(css|js|fonts|img)/ {
        access_log off;
        expires 1d;

        root /home/go/src/beeblog/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;
    }
}

部署完后,在浏览器输入ip地址:8080,浏览器显示超时,请问大佬如何解决呢?大佬又是怎么部署的呢?

Xavier-Zeng avatar Jul 11 '19 12:07 Xavier-Zeng

你这nginx配置的端口是80,所以你直接访问用ip访问就可以,不需要加8080端口(可能因为你的8080端口没有对外开放);如果你想测试项目是否启动,可以用在服务器上执行 curl localhost:8080;

上面这个nginx配置用了反向代理,所以你直接访问80端口,他会转发到8080端口上 `

location @backend {

    proxy_set_header X-Forwarded-For $remote_addr;

    proxy_set_header Host            $http_host;

    proxy_pass http://127.0.0.1:8080;
}

`

yirenyishi avatar Jul 16 '19 07:07 yirenyishi

你这nginx配置的端口是80,所以你直接访问用ip访问就可以,不需要加8080端口(可能因为你的8080端口没有对外开放);如果你想测试项目是否启动,可以用在服务器上执行 curl localhost:8080;

上面这个nginx配置用了反向代理,所以你直接访问80端口,他会转发到8080端口上 `

location @backend {

    proxy_set_header X-Forwarded-For $remote_addr;

    proxy_set_header Host            $http_host;

    proxy_pass http://127.0.0.1:8080;
}

`

谢谢大佬,成功解决了我的问题。 如果我修改listen 80;listen 8080;,在浏览器输入ip:8080,就能直接访问,而不用转发,这样理解对吗?

Xavier-Zeng avatar Jul 16 '19 08:07 Xavier-Zeng

对,但是一般网页默认会使用80端口,所以才会这样弄,不然就算你有域名,你也得加端口号,不友好

yirenyishi avatar Jul 16 '19 08:07 yirenyishi

你修改为8080的时候nginx的端口号和你的应用程序的端口号会冲突

yirenyishi avatar Jul 16 '19 08:07 yirenyishi

你修改为8080的时候nginx的端口号和你的应用程序的端口号会冲突

谢谢大佬的耐心解答

Xavier-Zeng avatar Jul 16 '19 08:07 Xavier-Zeng

这个代码有点老了,我和现在线上的版本不一样,我晚上回去更新一下github上代码

yirenyishi avatar Jul 16 '19 08:07 yirenyishi