分布式部署文档 - nginx 代理部署

  • 开头的行表示注释

  • $ 开头的行表示需要执行的命令
  • 系统: CentOS 7
  • IP: 192.168.100.100
  1. # 安装 nginx
  2. $ vi /etc/yum.repos.d/nginx.repo
  3.  
  4. [nginx]
  5. name=nginx repo
  6. baseurl=http://nginx.org/packages/centos/7/$basearch/
  7. gpgcheck=0
  8. enabled=1
  9.  
  10. # 非 Centos7 请参考 http://nginx.org/en/linux_packages.html#stable
  1. # 配置 Nginx
  2. $ vi /etc/nginx/nginx.conf
  3.  
  4. user nginx;
  5. worker_processes auto;
  6.  
  7. error_log /var/log/nginx/error.log warn;
  8. pid /var/run/nginx.pid;
  9.  
  10.  
  11. events {
  12. worker_connections 1024;
  13. }
  14.  
  15. stream {
  16. log_format proxy '$remote_addr [$time_local] '
  17. '$protocol $status $bytes_sent $bytes_received '
  18. '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
  19.  
  20. access_log /var/log/nginx/tcp-access.log proxy;
  21. open_log_file_cache off;
  22.  
  23. upstream MariaDB {
  24. server 192.168.100.10:3306;
  25. server 192.168.100.11:3306 backup; # 多节点
  26. server 192.168.100.12:3306 down; # 多节点
  27. # 这里是 Mariadb 的后端ip
  28. }
  29.  
  30. upstream cocossh {
  31. server 192.168.100.40:2222;
  32. server 192.168.100.40:2223; # 多节点
  33. # 这里是 coco ssh 的后端ip
  34. least_conn;
  35. }
  36.  
  37. server {
  38. listen 3306;
  39. proxy_pass MariaDB;
  40. proxy_connect_timeout 1s; # detect failure quickly
  41. }
  42.  
  43. server {
  44. listen 2222;
  45. proxy_pass cocossh;
  46. proxy_connect_timeout 1s; # detect failure quickly
  47. }
  48. }
  49.  
  50. http {
  51. include /etc/nginx/mime.types;
  52. default_type application/octet-stream;
  53. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  54. '$status $body_bytes_sent "$http_referer" '
  55. '"$http_user_agent" "$http_x_forwarded_for"';
  56.  
  57. access_log /var/log/nginx/access.log main;
  58.  
  59. sendfile on;
  60. # tcp_nopush on;
  61.  
  62. keepalive_timeout 65;
  63.  
  64. # 关闭版本显示
  65. server_tokens off;
  66.  
  67. include /etc/nginx/conf.d/*.conf;
  68. }
  1. # nginx 测试并启动, 如果报错请按报错提示自行解决
  2. $ nginx -t
  3. $ systemctl start nginx
  4.  
  5. # 访问 http://192.168.100.100
  6. # 默认账号: admin 密码: admin 到会话管理-终端管理 接受 Coco Guacamole 等应用的注册
  7. # 测试连接
  8. $ ssh -p2222 admin@192.168.100.100
  9. $ sftp -P2222 admin@192.168.100.100
  10. 密码: admin
  11.  
  12. # 如果是用在 Windows 下, Xshell Terminal 登录语法如下
  13. $ ssh admin@192.168.100.100 2222
  14. $ sftp admin@192.168.100.100 2222
  15. 密码: admin
  16. 如果能登陆代表部署成功
  17.  
  18. # sftp默认上传的位置在资产的 /tmp 目录下
  19. # windows拖拽上传的位置在资产的 Guacamole RDP上的 G 目录下