下載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/