Nginx不处理php文件并保存(php7.2-fpm)?

Nginx不处理php文件并保存(php7.2-fpm)Ubuntu18:04 </ p>

如何正确设置nginx以使用php7.2 </ p>

/ etc / nginx / sites-available / default </ h1>

  server {
listen 80 default_server;
listen [::]:80 default_server;

#SSL配置

#listen 443 ssl default_server;
#listen [::]: 443 ssl default_server;

#注意:您应该为SSL流量禁用gzip。
#请参阅:https://bugs.debian.org/773332

#阅读ssl_ciphers以确保安全 配置。
#请参阅:https://bugs.debian.org/765782

#ssl-cert软件包生成的自签名证书
#不要在生产服务器中使用它们!


#include snippets / snakeoil.conf;

root / var / www / html;

#如果您使用PHP
index index.php index.html index,请将index.php添加到列表中。 htm index.nginx-debian.html;

server_name _;

location / {
#首先尝试将请求作为文件提交,然后
#作为目录,然后回退到显示404.
try_files $ uri $ uri / = 404;
}

#toc PHP 脚本到FastCGI服务器

location~ \ .php $ {
include snippets / fastcgi-php.conf;

##使用php-fpm(或其他unix套接字):
fastcgi_pass unix:/ var / run / php / php7.2-fpm.sock;
##使用php-cgi(或其他tcp套接字):
#fastcgi_pass 127.0.0.1:9000;
}

#拒绝访问 .htaccess文件,如果Apache的文档root
#与nginx的一个

位置同意〜/.ht {
deny all;
}
</ code> </ pre>

< p>} </ p>

/etc/nginx/sites-available/test.ru </ h1>

  server {

listen 80; \ n
listen [::]:80;

root /var/www/test.ru/html;
nn index index.php index.html index.htm index.nginx-debian.html; \ n
server_name test.ru www.test.ru;

location / {

try_files $ ur i $ uri / = 404;

}

}
</ code> </ pre>

sudo service nginx reload
sudo nginx -t </ p>
\ n

  nginx:配置文件/etc/nginx/nginx.conf语法正常
nginx:配置文件/etc/nginx/nginx.conf测试成功
</ code> </ pre>

这种行为的原因是什么? 如何设置?</ p>
</ div>

展开原文

原文

Nginx does not process the php file and saves it (php7.2-fpm) Ubuntu18:04

How to set up correctly nginx for working with php7.2

/etc/nginx/sites-available/default

   server {
    listen 80 default_server;
    listen [::]:80 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.2-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny all;
    }

}

/etc/nginx/sites-available/test.ru

 server {

 listen 80;

 listen [::]:80;

 root /var/www/test.ru/html;

 index index.php  index.html index.htm index.nginx-debian.html;

 server_name test.ru www.test.ru;

 location / {

         try_files $uri $uri/ =404;

 }

 }

sudo service nginx reload sudo nginx -t

 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
 nginx: configuration file /etc/nginx/nginx.conf test is successful

What is the reason for this behavoir ? How to set it up?

dongsheng8664
dongsheng8664 不,但我尝试过它的确有效!
2 年多之前 回复
douliang2167
douliang2167 您是否尝试将php部分复制到第二个站点配置?
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐