一个服务器可以为一些网站和Apache Nginx的反向代理别人跑Nginx的? [英] Can a server run Nginx for some sites and Apache Nginx Reverse Proxy for others?

查看:157
本文介绍了一个服务器可以为一些网站和Apache Nginx的反向代理别人跑Nginx的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一台服务器的理想我想为我自己的静态和Word preSS使用的CloudFlare>光油> Nginx的网站,但因为我还可以举办其他网站进行测试,如依赖Joomla和字preSS在使用的.htaccess和等多个扩展名,我不能够很容易地通过运行Nginx的这些网站。所以我想来运行的CloudFlare>光油> Nginx的反向代理服务器> Apache在同一个服务器上的这些网站。

服务器只具有1的IP地址,并运行Ubuntu和PHP-FPM和MySQL。每个站点将有自己独立的域名。这将是可能的吗?


解决方案

 服务器{
    SERVER_NAME example.com;
    位置 / {
        #假设Apache是​​在例如81端口
        proxy_pass http://127.0.0.1:81;
        #使阿帕奇检测主机头
        proxy_set_header $ host主机;
    }#如果你有资产的文件夹,可以让nginx的直接为他们服务,
#强似他们阿帕奇    位置/图片{#或/ CSS或/ JS等..
        try_files $ URI = 404;
    }
}

注:资产的情况下,有时会出现一些网站通过重写服务资产,甚至可以由应用它的自我处理,您可以通过添加将它传递给apache的,在资产所在地为这样一个后备

 位置/图片{
    try_files $ URI @apache;
}
位置@apache {
    proxy_pass http://127.0.0.1:81;
}

在Apache中创建一个虚拟主机

 <虚拟主机*:81>
    服务器名称example.com
    #如果需要,配置其余
< /虚拟主机>

On a server ideally I'd serve my own static and WordPress sites using Cloudflare > Varnish > Nginx but since I'd also be hosting others sites for testing such as Joomla and WordPress that rely on multiple extensions that use .htaccess and such, I wouldn't be able to easily run those sites through Nginx. So I'd like to run those sites on the same server with CloudFlare > Varnish > Nginx Reverse Proxy > Apache.

The server only has 1 ip address and runs ubuntu and php-fpm and mysql. Each site would have their own separate domain name. Would this be possible?

解决方案

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;
    }
}

Note: in the case of assets, sometimes some sites serve assets through rewrites, or even handled by the application it self, you can pass it to apache by adding that in the assets location as a fallback like this

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

In apache you create a virtual host

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

这篇关于一个服务器可以为一些网站和Apache Nginx的反向代理别人跑Nginx的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆