Nginx (在Ubuntu 22.04上)不能为一个域名处理php。

20 浏览
0 Comments

Nginx (在Ubuntu 22.04上)不能为一个域名处理php。

我正在一个Droplet(Digital Ocean)中安装一个网站。我安装NGINX和PHP时出了问题。我看了一篇教程https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04,但是当我尝试运行一些.php文件时,它们只是被下载下来了...例如... http://5.101.99.123/info.php可以工作,但是...如果我去 http://5.101.99.123,它会下载我的index.php:/

有什么想法吗?

-rw-r--r--  1 agitar_user www-data   418 Jul 31 18:27 index.php
-rw-r--r--  1 agitar_user www-data    21 Aug 31 11:20 info.php

我的/etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        root /var/www/html;
        index index.html index.htm index.php;
        # Make site accessible from http://localhost/
        server_name agitarycompartir.com;
               location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    ## NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #               # With php5-cgi alone:
    #               fastcgi_pass 127.0.0.1:9000;
    #               # With php5-fpm:
                    fastcgi_pass unix:/var/run/php5-fpm.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
            }
              location / {
                    try_files $uri $uri/ =404;
                    # Uncomment to enable naxsi on this location
                    # include /etc/nginx/naxsi.rules
            }

...

其他\"locations\"被注释了...

.

admin 更改状态以发布 2023年5月23日
0
0 Comments

我曾遇到类似问题,通过清空浏览器缓存(在不同的浏览器中也有效)解决了问题。

0
0 Comments

尝试以下操作:

  1. 编辑/etc/nginx/sites-available/default文件

  2. 取消注释两行listen语句,使Nginx在IPv4和IPv6的80端口上监听。

     listen   80; ## listen for ipv4; this line is default and implied
     listen   [::]:80 default_server ipv6only=on; ## listen for ipv6
    

  3. 保持server_name不变

     # Make site accessible (...)
     server_name localhost;
    

  4. index行中添加index.php

     root /usr/share/nginx/www;
     index index.php index.html index.htm;
    

  5. 取消注释location ~ \.php$ {}语句

     # pass the PHP scripts to FastCGI server listening on (...)
     #
     location ~ \.php$ {
             try_files $uri =404;
             fastcgi_split_path_info ^(.+?\.php)(/.+)?$;
             # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
             # With php5-cgi alone:
             #fastcgi_pass 127.0.0.1:9000;
             # With php5-fpm:
             fastcgi_pass unix:/var/run/php5-fpm.sock;
             fastcgi_index index.php;
             include fastcgi_params;
     }
    

  6. 编辑/etc/php5/fpm/php.ini文件,并确保cgi.fix_pathinfo被设置为0

  7. 重新启动Nginx和php5-fpmsudo service nginx restart && sudo service php5-fpm restart


我是在一周前才开始使用Linux的,所以我真的希望能帮助您。我使用的是nano文本编辑器来编辑文件。如果您没有,可以运行apt-get install nano进行安装。Google一下了解更多信息。

0