[英]Nginx as reverse proxy for Apache not working - serving static file
I configured a vps server with nginx, php-fpm and apache on it. 我用nginx,php-fpm和apache配置了一个vps服务器。
Usual web sites with .html extension
are serverd as static web pages like
normal , but when I try to use .php page which dynamically generate content I see only pure html code like Nginx is serving .txt file.
通常,具有.html扩展名的
网站
都像
正常服务器一样作为静态网页进行服务器处理,但是当我尝试使用.php页面来动态生成内容时,我看到只有纯html代码(例如Nginx)正在提供.txt文件。
Nginx listens on 80, Apache on 8080. Nginx监听80,Apache监听8080。
Mods disabled: mod_proxy, mod_actions
禁用Mods:
mod_proxy, mod_actions
Nginx server block configuration: Nginx服务器块配置:
server {
server_name example.com www.example.com;
listen 80;
root /var/www/example.com;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://IP:8080;
}
}
Apache virtual host configuration: Apache虚拟主机配置:
<VirtualHost *:8080>
DocumentRoot /var/www/example.com
ServerName example.com
<Directory />
AllowOverride All
</Directory>
</VirtualHost>
Nginx & Apache both work under %username%, using %username% as group too. Nginx和Apache都在%username%下工作,也使用%username%作为组。
Code seems to be correct, but the problem is when I load webpage example.com/index.php it is loaded like a .txt file with pure html code instead of normal .php page. 代码似乎是正确的,但是问题是当我加载网页example.com/index.php时,它像使用纯html代码而不是常规.php页面的.txt文件一样被加载。
Same with info.php with usual "<?php phpinfo(); ?>"
与info.php相同,通常使用
"<?php phpinfo(); ?>"
I see code but not real info
page .
我看到了代码,但没有看到真正的信息
页面 。
You need to configure either nginx
or Apache to send the file to the php interpreter. 您需要配置
nginx
或Apache才能将文件发送到php解释器。
See this document to use nginx
and php-fpm
with the fastcgi_pass
directive. 请参阅本文档以将
nginx
和php-fpm
与fastcgi_pass
指令一起使用。
See this document to use Apache and mod_php
. 请参阅本文档以使用Apache和
mod_php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.