nginx和php7.2-fpm仅适用于IP地址



我的 Nginx/php7.2-fpm 上的 Php 脚本仅适用于默认配置和 IP 地址,不适用于域名或子域...

我的配置:

默认配置

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name _;
    location / {
            try_files $uri $uri/ =404;
    }
    location ~ .php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}

我的域配置:

server {
        listen 80;
        listen [::]:80;
        root /home/fluke667/html/web.mydomain.com/web;
        index index.php index.html index.htm index.nginx-debian.html;
        server_name web.mydomain.com;
        location / {
                try_files $uri $uri/ =404;
        }
}

Nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
        worker_connections 768;
        # multi_accept on;
}
http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
    include /etc/nginx/mime.types;
    #default_type application/octet-stream;
    default_type        text/html;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

没有该子域和 IP,它可以在/var/www/html 中工作不知道为什么,any1 可以帮助我吗?

nginx wordpress抄本

为例
    location / {
       try_files $uri $uri/ /index.php?$args;
    }
    location ~ .php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

这意味着对于此server块中的任何请求,第一个位置块很可能会运行。它将首先try查找静态文件,然后尝试查找具有该请求路径的目录,最后将其发送到index.php。当发送到index.php时,将运行location ~ .php$的第二个位置块,它将向php7.2-fpm.sock发送文件扩展名php的所有请求

您目前有 2 个server块。一个在Default Config,一个在My Domain Config.您在自定义 conf 中具有server_name web.mydomain.com;,这意味着对该主机的任何请求都将由该server块应答。任何其他主机将由Default Config(包括 IP)处理。

最新更新