简体   繁体   English

使用Nginx和Apache的virtualhost

[英]virtualhost with nginx and Apache

I have set up my local machine with nginx and apache. 我已经用nginx和apache设置了本地计算机。 I use nginx as a frontend-server for all nodejs communication. 我将nginx用作所有nodejs通信的前端服务器。 Every nodejs application has an own upstream defined and an entry in my hosts file, so that I get a handy URL to work with. 每个nodejs应用程序都有一个自己的上游定义,并在我的hosts文件中有一个条目,因此我可以使用一个方便的URL。 Also, i have one upstream defined for apache, which works on port 8080 in my config - so that all my php applications are available under localhost/* (internally it is localhost:8080/*). 另外,我为apache定义了一个上游,它在我的配置中的端口8080上工作-这样我所有的php应用程序都可以在localhost / *下使用(内部是localhost:8080 / *)。 This configuration is working fine for several month now. 此配置现在可以正常工作几个月。 But this time I would like to set up a magento installation on my local machine. 但是这一次,我想在本地计算机上设置一个magento安装。 For this purpose I added 127.0.0.1 magento.local to my hosts file (like I did for all nodejs applications) and added the following to my nginx.conf: 为此,我将127.0.0.1 magento.local添加到了我的主机文件(就像我对所有nodejs应用程序所做的那样),并将以下内容添加到了我的nginx.conf中:

upstream apache {
    server 127.0.0.1:8080;
}

server {
    listen       80;
    server_name  magento.local;
    client_max_body_size    1024M;
    root /Users/phunkei/htdocs/magento;
    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://apache;
    }
}

This rewrites everything to /Users/phunkei/htdocs/ , which is my root for apache. /Users/phunkei/htdocs/所有内容重写为/Users/phunkei/htdocs/ ,这是我的Apache根目录。 I already tried to add a subfolder to the upstream definition server 127.0.0.1:8080/magento , but nginx does not allow that. 我已经尝试将子文件夹添加到上游定义server 127.0.0.1:8080/magento ,但是nginx不允许这样做。

Currently you proxy everything, so http://magento.local/ points to http://localhost:8080/ . 当前,您代理了所有内容,因此http://magento.local/指向http://localhost:8080/

If you want http://magento.local/ to point to http://localhost:8080/magento/ you need to use: 如果要http://magento.local/指向http://localhost:8080/magento/ ,则需要使用:

proxy_pass http://apache/magneto/;

If you want to serve some static content directly from nginx using your root /Users/phunkei/htdocs/magento , you will need to add directives to achieve that, such as moving the proxy code into a named location and using try_files : 如果您想使用root /Users/phunkei/htdocs/magento直接从nginx提供一些静态内容,则需要添加指令来实现这一目标,例如将代理代码移至指定位置并使用try_files

location / {
  try_files $uri $uri/ @proxy;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM