【问题标题】:Cannot access all web servers from outside network无法从外部网络访问所有 Web 服务器
【发布时间】:2017-08-21 04:21:27
【问题描述】:

我有两个 apache 网络服务器,每个都在一个单独的树莓派上运行。 Pi A 运行网站 1,pi B 运行网站 2。 Pi A 也设置为我的 DNS 服务器(并且在 /etc/hosts 中有 pi B 的信息),我的路由器有端口 80 和 443 转发给它。虽然在我的本地网络上一切正常,但我可以访问这两个网站。离线我只能访问网站 1。当我尝试访问网站 2 时,我只能从 pi A 获得默认的 apache 页面。有什么想法吗?

【问题讨论】:

标签: apache raspberry-pi


【解决方案1】:

您可以使用类似的虚拟主机配置在前端配置 nginx:

server {
    listen 443;
    server_name _;
    ssl on;
    ssl_certificate         /srv/nginx/file.crt;
    ssl_certificate_key     /srv/nginx/file.key;

location /site1 {
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://127.0.0.1:8443;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

location /site2 {
    proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass https://192.168.0.20:8443;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;
}

Nginx安装很简单:

yum install nginx
service nginx start

您还需要将 apache 端口从默认值编辑为 8080 或 8443,例如。

【讨论】:

    猜你喜欢
    • 2018-08-22
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 2020-02-24
    • 2017-05-19
    相关资源
    最近更新 更多