[英]php is being downloaded instead of being loaded
我得到了一個實際工作的 nginx docker 容器。 因為當我在我的主機上執行curl localhost:7070
時,我會得到站點的內容作為返回。 然后我在我的主機上為 nginx 進行了配置,問題是當我嘗試在瀏覽器中打開該站點時,它會下載 php 文件。 我將介紹主機 nginx 和 docker nginx 的兩個配置。
Nginx 主機配置:
server {
#listen 80 default_server;
#listen [::]:80 default_server;
# SSL configuration
listen 7171 ssl default_server;
listen [::]:7171 ssl default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name SERVERNAME;
location / {
proxy_pass http://127.0.0.1:7070;
#proxy_redirect off;
#proxy_set_header Host $host;
#proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Host $server_name;
}
}
nginx docker 配置:
server {
listen 80;
server_name default_server;
root /usr/share/nginx/selfoss;
index index.php index.html;
location ~* \ (gif|jpg|png) {
expires 30d;
}
location ~ ^/(favicons|thumbnails)/.*$ {
try_files $uri /data/$uri;
}
location ~* ^/(data\/logs|data\/sqlite|config\.ini|\.ht) {
deny all;
}
location / {
index index.php;
try_files $uri /public/$uri /index.php$is_args$args;
}
}
我對 nginx 正常配置知之甚少,但我在 php 是新手,所以我在這里缺少什么?
我看過關於 php-fpm 和 fastcgi 的帖子,但我不知道如何或在哪里進行配置更改。
您在 Nginx-Config 中缺少配置的 PHP-FPM,當然還有正在運行的 PHP-FPM(在同一個 Docker-Container 或單獨的 Docker-Container 中)。
server{}
部分內的示例 Nginx-Config
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
proxy_read_timeout 300;
fastcgi_read_timeout 300;
fastcgi_pass unix:/var/run/sockets/php/www.sock;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.