【问题标题】:Can a server run Nginx for some sites and Apache Nginx Reverse Proxy for others?服务器可以为某些站点运行 Nginx 并为其他站点运行 Apache Nginx 反向代理吗?
【发布时间】:2013-08-21 19:47:21
【问题描述】:

在理想情况下,在服务器上,我会使用 Cloudflare > Varnish > Nginx 为我自己的静态和 WordPress 网站提供服务,但因为我还会托管其他网站进行测试,例如 Joomla 和 WordPress,它们依赖于使用 .htaccess 和这样,我将无法通过 Nginx 轻松运行这些站点。所以我想用 CloudFlare > Varnish > Nginx Reverse Proxy > Apache 在同一台服务器上运行这些站点。

服务器只有1个ip地址,运行ubuntu和php-fpm和mysql。每个站点都有自己独立的域名。这可能吗?

【问题讨论】:

  • 这里没有听到任何人的意见。在 Twitter 上尝试过,有人提到这应该不是问题,使用 nginx 运行一些站点和一些使用 nginx 反向代理运行 apache 的站点/域。希望这里有人能够证实这一点。然后我只需要对如何自行实施它进行更多研究。
  • 不确定问题出在哪里:您当然可以通过 nginx 为多个站点提供服务。您可以分别配置它们中的每一个。所以:是的,你可以。
  • 只需安装apache并在不同的端口上运行它,然后proxy_pass它们从nginx到apache的端口
  • @MichaelHärtl 对,但我的问题不是我可以通过 nginx 为多个站点提供服务,我上面的问题是我可以通过常规 nginx(例如 example1.com 和 example2.com)提供一些服务器,然后服务器 example3 .com 和 example4.com 通过 nginx 反向代理到 apache。 (在同一台服务器上)。 Modammad 您的解决方案会在那种情况下工作吗?我对 proxy_pass 不熟悉,但如果可以,请将其添加为答案。
  • *在上述评论中的意思是“我可以发球/然后发球”而不是“我可以发球/然后发球”

标签: apache ubuntu nginx


【解决方案1】:
server {
    server_name example.com;
    location / {
        # assuming apache is on port 81 for example
        proxy_pass http://127.0.0.1:81;
        # to make apache detect the host header
        proxy_set_header Host $host;
    }

# if you have assets folders, you can let nginx serve them directly,
# instead of passing them to apache

    location /images { # or /css or /js .. etc
        try_files $uri =404;
    }
}

注意:在资产的情况下,有时某些网站通过重写来提供资产,甚至由应用程序自己处理,您可以通过将其添加到资产位置作为这样的后备来将其传递给 apache

location /images {
    try_files $uri @apache;
}
location @apache {
    proxy_pass http://127.0.0.1:81;
}

在 apache 中创建一个虚拟主机

<VirtualHost *:81>
    ServerName example.com
    # the rest of the config if needed
</VirtualHost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-09
    • 2018-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 1970-01-01
    • 2011-04-25
    相关资源
    最近更新 更多