`
chengpeng_2015
  • 浏览: 6824 次
社区版块
存档分类
最新评论

Nginx配置多域名转发到不同服务

阅读更多

1.背景描述

现有一台服务器,8080及8081端口分别有两个服务,需要做到访问域名chengp.net的请求转发8080服务,访问域名myexception.net的请求转发到8081云服务。

2.Nginx搭建

参考另一篇文章《Docker安装Nginx》

3.配置Nginx

  1. user nginx;
  2. worker_processes 1;
  3. error_log /var/log/nginx/error.log warn;
  4. pid /var/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. server {
  10. listen 80;
  11. server_name chengp.net www.chengp.net;
  12. location /{
  13. proxy_pass http://39.108.67.52:8080;
  14. }
  15. }
  16. server {
  17. listen 80;
  18. server_name myexception.net www.myexception.net;
  19. location /{
  20. proxy_pass http://39.108.67.52:8081;
  21. }
  22. }
  23. include /etc/nginx/mime.types;
  24. default_type application/octet-stream;
  25. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  26. '$status $body_bytes_sent "$http_referer" '
  27. '"$http_user_agent" "$http_x_forwarded_for"';
  28. access_log /var/log/nginx/access.log main;
  29. sendfile on;
  30. #tcp_nopush on;
  31. keepalive_timeout 65;
  32. #gzip on;
  33. include /etc/nginx/conf.d/*.conf;
  34. }

在http模块添加了两个server节点,修改好后重启Nginx服务即可。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics