反向代理不起作用

反向代理不起作用

我正在尝试将 nginx 配置为反向代理:

apache:监听本地主机:8777 nginx:监听端口 80

但是我转到 http:/blog.example.com/blog,浏览器输出:

错误 -http://blog.example.com:8777/

请勿下载页面'http://blog.example.com:8777/“”。

无法连接到目标 (blog.example.com)

我的nginx.conf如下:

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log;
pid        /run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    index   index.html index.htm;
    include /etc/nginx/conf.d/*.conf;
    server {
        listen       80 default_server;
        server_name  blog.example.com;
        root         /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;
        location / {
       proxy_pass http://localhost:8777;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        }
        error_page  404              /404.html;
        location = /40x.html {
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        }
    }
}

奇怪的是,如果我手动创建了一个 html 文件,则不会出现问题,内容会显示出来。我做错了什么?

相关内容