问题描述
我在 digitalocean 有一个 ubuntu 服务器,我试图让 PHP 工作。 我已经成功地使用 Nginx 创建了一个子域,尽管 Nginx 一直在下载 PHP 文件,而不是为它们提供服务。这是我的默认设置:
server {
listen 80;
listen [::]:80;
index index.html index.PHP;
server_name _;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
我尝试将以下内容添加到默认的 Nginx 文件中,但没有成功:
location ~ \.PHP$ {
include snippets/fastcgi-PHP.conf;
fastcgi_pass unix:/run/PHP/PHP7.3-fpm.sock;
}
完成:
server {
listen 80;
listen [::]:80;
index index.html index.PHP;
server_name _;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location ~ \.PHP$ {
include snippets/fastcgi-PHP.conf;
fastcgi_pass unix:/run/PHP/PHP7.3-fpm.sock;
}
}
我开始认为“location / {”是针对所有内容的,还是某处存在配置错误?如果我将 html 文件添加到子域,它就可以正常工作,然后 Nginx 会正确地为它们提供服务,但不能为 PHP 提供服务。
server {
listen 80;
index index.PHP index.html;
server_name sub.example.com;
error_log /var/log/Nginx/error.log;
access_log /var/log/Nginx/access.log;
root /home/simonduun/sub;
location ~ \.PHP$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.PHP;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.PHP?$query_string;
gzip_static on;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/wp-json/ {
rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)