Nginx 作为 Apache 的反向代理不起作用 - 提供静态文件
Nginx as reverse proxy for Apache not working - serving static file
我用 nginx、php-fpm 和 apache 配置了一个 vps 服务器。
带有 .html 扩展名 的普通网站 是 serverd 作为静态网页,如 normal,但是当我尝试使用动态生成内容的 .php 页面时,我只看到像 Nginx 这样的纯 html 代码正在提供 .txt 文件。
Nginx 在 80 上侦听,Apache 在 8080 上侦听。
模组禁用:
mod_proxy, mod_actions
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 虚拟主机配置:
<VirtualHost *:8080>
DocumentRoot /var/www/example.com
ServerName example.com
<Directory />
AllowOverride All
</Directory>
</VirtualHost>
Nginx 和 Apache 都在 %username% 下工作,也使用 %username% 作为组。
代码似乎是正确的,但问题是当我加载网页示例时。com/index.php 它像 .txt 文件一样加载,使用纯 html 代码而不是正常.php 页.
与 info.php 相同,通常 "<?php phpinfo(); ?>"
我看到代码但不是真实的信息页面。
您需要配置 nginx
或 Apache 以将文件发送到 php 解释器。
请参阅 this document 以将 nginx
和 php-fpm
与 fastcgi_pass
指令一起使用。
请参阅 this document 以使用 Apache 和 mod_php
。
我用 nginx、php-fpm 和 apache 配置了一个 vps 服务器。
带有 .html 扩展名 的普通网站 是 serverd 作为静态网页,如 normal,但是当我尝试使用动态生成内容的 .php 页面时,我只看到像 Nginx 这样的纯 html 代码正在提供 .txt 文件。
Nginx 在 80 上侦听,Apache 在 8080 上侦听。
模组禁用:
mod_proxy, mod_actions
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 虚拟主机配置:
<VirtualHost *:8080>
DocumentRoot /var/www/example.com
ServerName example.com
<Directory />
AllowOverride All
</Directory>
</VirtualHost>
Nginx 和 Apache 都在 %username% 下工作,也使用 %username% 作为组。
代码似乎是正确的,但问题是当我加载网页示例时。com/index.php 它像 .txt 文件一样加载,使用纯 html 代码而不是正常.php 页.
与 info.php 相同,通常 "<?php phpinfo(); ?>"
我看到代码但不是真实的信息页面。
您需要配置 nginx
或 Apache 以将文件发送到 php 解释器。
请参阅 this document 以将 nginx
和 php-fpm
与 fastcgi_pass
指令一起使用。
请参阅 this document 以使用 Apache 和 mod_php
。