我正在尝试在Windows WSL上使用nginx php 7.1和mariadb创建本地Web服务器。 我尝试了很多事情,使用Kali,使用Debian,使用Ubuntu,更改了nginx端口而不是80,我发现了一些我尝试过的nginx配置,但是没有用。
我的问题是php无法通过nginx处理。
当我尝试加载简单的php页面<?php echo 'ok'; ?>
时,它会无限加载。
但是当我重新启动php7.1-fpm时,页面正常工作! (只有当我尝试加载时,才有一次)
这是我实际的默认Nginx配置文件:
server {
listen 32000 default_server;
listen [::]:32000 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
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 _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
#fastcgi_pass 127.0.0.1:9000;
# I tried this too :
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
当我运行php index.php
时,它也起作用。但是在firefox上,加载该文件没有任何反应。完整的html页面一切都很好。我也得到了nginx欢迎页面,没有问题。
我不知道在哪里看。感谢您的阅读,如果您有任何答案,非常感谢!
答案 0 :(得分:-1)
这是我的:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME D:/web/html$fastcgi_script_name;
include fastcgi_params;
try_files = $uri @missing;
}
还要确保PHP-CGI正在运行(并且在正确的端口上)。