将域名转发到本地端口 首先介绍最常用的,将域名转发到本地另一个端口上 server{ listen 80; server_name top1.cm; index index.php index.html index.htm; location / { proxy_pass http://127.0.0.1:88; proxy_set_header Host $proxy_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 这样访问 http://tomcat.shaochenfeng.com 时就会转发到本地的 8080 端口 ###################################################################################### 将域名转发到另一个域名 server{ listen 80; server_name baidu.shaochenfeng.com; index index.php index.html index.htm; location / { proxy_pass http://www.baidu.com; proxy_set_header Host $proxy_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 这样访问 http://baidu.shaochenfeng.com 时就会转发到 http://www.baidu.com ################################################################################### 本地一个端口转发到另一个端口或另一个域名 server{ listen 80; server_name 127.0.0.1; # 公网ip index index.php index.html index.htm; location / { proxy_pass http://127.0.0.1:8080; # 或 http://www.baidu.com proxy_set_header Host $proxy_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 这样访问 http://127.0.0.1 时就会转发到本地的 8080 端口或 http://www.baidu.com