1、安装nginx

    yum -y install nginx

2、启动nginx

    service nginx start

3、访问(nginx默认是80端口)

    curl 127.0.0.1

4、域名子绑定

    编辑文件/etc/nginx/conf.d/default.conf,在底部加入下面代码,完成前几章所述4个端口的子域名绑定

  1. server{
  2. listen 80;
  3. server_name tomcat.bingzhenmifan.com;
  4. location /
  5. {
  6. proxy_set_header Host $host;
  7. proxy_set_header X-Real-Ip $remote_addr;
  8. proxy_set_header X-Forwarded-For $remote_addr;
  9. proxy_pass http://127.0.0.1:14802;
  10. }
  11. }
  12.  
  13. server{
  14. listen 80;
  15. server_name jetty.bingzhenmifan.com;
  16. location /
  17. {
  18. proxy_set_header Host $host;
  19. proxy_set_header X-Real-Ip $remote_addr;
  20. proxy_set_header X-Forwarded-For $remote_addr;
  21. proxy_pass http://127.0.0.1:14808;
  22. }
  23. }
  24.  
  25. server{
  26. listen 80;
  27. server_name resin8080.bingzhenmifan.com;
  28. location /
  29. {
  30. proxy_set_header Host $host;
  31. proxy_set_header X-Real-Ip $remote_addr;
  32. proxy_set_header X-Forwarded-For $remote_addr;
  33. proxy_pass http://127.0.0.1:8080;
  34. }
  35. }
  36.  
  37. server{
  38. listen 80;
  39. server_name resin14805.bingzhenmifan.com;
  40. location /
  41. {
  42. proxy_set_header Host $host;
  43. proxy_set_header X-Real-Ip $remote_addr;
  44. proxy_set_header X-Forwarded-For $remote_addr;
  45. proxy_pass http://127.0.0.1:14805;
  46. }
  47. }

5、重启nginx

    service nginx restart

6、访问测试

    依次访问上面4个域名:tomcat.bingzhenmifan.com、jetty.bingzhenmifan.com、resin8080.bingzhenmifan.com、resin14805.bingzhenmifan.com

    注意:如果域名没有备案的话,在本地是打不开网站的,可以在云服务器上使用curl命令访问

7、域名备案

    登录阿里云,点击右上角【备案】,按步骤完成备案即可

版权声明:本文为liaolongjun原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/liaolongjun/p/5664005.html