2015-11-23 80 views
0

我用nginx和apache建立了本地机器。我使用nginx作为所有nodejs通信的前端服务器。每个nodejs应用程序都有自己的上游定义,并在我的hosts文件中有一个条目,这样我就可以得到一个方便的URL。另外,我有一个为apache定义的上游,它在我的配置中工作在端口8080上 - 这样我所有的php应用程序都可以在localhost/*(内部是localhost:8080/*)下使用。此配置现在可以正常工作几个月。但是这次我想在本地机器上安装magento安装。为此我加入127.0.0.1 magento.local我的hosts文件(像我一样对所有应用程序的NodeJS),并增加了以下我的nginx.conf:带有nginx和Apache的虚拟主机

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

这改写一切/Users/phunkei/htdocs/,这是我的Apache根。我已经尝试向上游定义server 127.0.0.1:8080/magento添加子文件夹,但nginx不允许这样做。

+0

不知道你想达到的目标。但是'root'语句是多余的。它不是必需的,也没有使用。你想要做'proxy_pass http:// apache/magneto /;'? –

+0

是的,它会为网址添加“magento”,导致产生“http:// magento.local/magento”。我试图让'http://magento.local/'point到'/ Users/phunkei/htdocs/magento'或'http:// localhost:8080/magento' – Daniel

回答

0

目前你代理一切,所以http://magento.local/指向​​。

如果你想http://magento.local/指向http://localhost:8080/magento/你需要使用:

proxy_pass http://apache/magneto/; 

如果你想从nginx使用root /Users/phunkei/htdocs/magento直接服务于一些静态的内容,你将需要添加指令来实现这一点,这样的作为移动代理代码到指定位置,并使用try_files

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

我已经尝试过'proxy_pass http:// apache/magento /;',但它导致302重定向到'http:// localhost/magento /' – Daniel

+0

302看起来像是来自'apache'而不是'nginx'。 apache访问日志说什么? –