编辑。
问题已经在这里得到了答案:https :
//serverfault.com/questions/889334/cant-get-nginx-to-run-php-on-ubuntu-16-04-server
我正在设置运行nginx的服务器,并且试图使其运行php脚本。
显然,关于如何使Nginx运行php的最伟大的文章是这篇文章:https : //www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in- ubuntu-16-04
随着其他方向的发展,下面的讨论就此结束。
在nginx上启用PHP的最简单方法是什么?
我遵循数字海洋网站上的指示,但没有任何变化,我仍然无法运行php。
我对此很迷失,不胜感激。
这是输出sudo service nginx status
:
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2017-12-17 13:46:33 GMT; 55min ago
Process: 19056 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 19091 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Process: 19064 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 19059 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 19066 (nginx)
Tasks: 2
Memory: 4.6M
CPU: 406ms
CGroup: /system.slice/nginx.service
├─19066 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
└─19094 nginx: worker process
Dec 17 13:46:33 websites systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec 17 13:46:33 websites systemd[1]: Started A high performance web server and a reverse proxy server.
Dec 17 13:48:53 websites systemd[1]: Reloading A high performance web server and a reverse proxy server.
Dec 17 13:48:53 websites systemd[1]: Reloaded A high performance web server and a reverse proxy server.
这是输出php -v
:
PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.22-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
这是我正在使用的配置文件。
它在/etc/nginx/conf.d/virtual_servers.conf
。
server {
listen 80;
server_name openage.org www.openage.org;
#listen [::]:80 default_server ipv6only=on;
#root /usr/share/nginx/html;
root /etc/nginx/html/openage;
index index.php index.html index.htm;
#server_name localhost;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/openage.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/openage.org/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我已经:
- 重新启动php-fpm。
- 重新启动了nginx。
- 强制使用ctrl-f5重新加载浏览器缓存。
- 检查了/ var / log / error是否有错误,但是当我运行php文件时,显然没有错误。就像nginx只是没有意识到它应该运行php一样,而不是像对待常规文件一样对待它。
我正在尝试运行仅包含功能的脚本phpinfo()
。但是浏览器并没有给我PHP信息,而是让我下载文件。/
:
我将其添加到问题。
—
Hermann Ingjaldsson
您是如何配置php的?将您的配置编辑发布到php和nginx。重新启动php-fpm和nginx,清除浏览器缓存,在您的nginx日志中查找错误,什么php脚本???我们需要更多信息。
—
豹
您得到的错误消息是什么?
—
George Udosen '17
@HermannIngjaldsson您的nginx状态看起来不错,究竟是什么错误?
—
MehrdadEP
sudo service nginx status
和php -v