1.问题描述:
访问www.localhost:80和www.localhost:80/api走不同的后台服务,www.localhost:80反向代理成百度,www.baidu.com; www.localhost:80/api反向代理成www.runoob.com (菜鸟官网)
2.配置文件
windows版
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /aa {
proxy_pass http://www.baidu.com/ ; #对的
}
location /bb/ {
proxy_pass https://docs.open.alipay.com ; #错的
}
location /cc{
proxy_pass https://docs.open.alipay.com/ ; #对的
}
location / {
proxy_pass http://www.runoob.com ; #对的
}
#error_page 404 /404.html;
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
3.注意事项
1)
location /cc{
proxy_pass https://docs.open.alipay.com/ ; #这种格式是对的。
}
2):启动,关闭,重启的时候,使用命令行
3): 浏览器,内外网问题