下载GOFLY客服(go语言开发的在线客服系统)系统后 ,运行起来服务 ,默认是监听8081端口
这个时候,只能使用http://ip:8081这样的形式来访问 ,不符合实际需求
下载安装配置nginx后,就可以通过域名来访问服务了
ubuntu系统安装nginx
apt-get install curl gnupg2 ca-certificates lsb-release echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" | tee /etc/apt/sources.list.d/nginx.list curl -fsSL https://nginx.org/keys/nginx_signing.key | apt-key add - apt-key fingerprint ABF5BD827BD9BF62 apt-get update apt-get install nginx
centos系统安装nginx
vim 编辑 /etc/yum.repos.d/nginx.repo
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
yum install nginx
配置nginx反向代理
location /static { } 这里配置的是,访问静态资源的时候,直接nginx返回静态资源,就不用走到go后端服务了
proxy_pass http://127.0.0.1:8081; 这里就是重点了,反向代理到后端8081端口
下面这几句是传递真实IP到后端服务
proxy_set_header X-Real-IP $remote_addr;
升级连接成为websocket连接 , 支持websocket
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Origin "";
server{ listen 80; server_name gofly.sopans.com; access_log /var/log/nginx/gofly.sopans.com.access.log main; location /static { root /var/www/html/go-fly;//自己的部署路径,静态文件直接nginx响应 } location / { proxy_pass http://127.0.0.1:8081; proxy_http_version 1.1; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Origin ""; } }
在线客服系统的访问网址:https://gofly.sopans.com/