【问题标题】:nginx and php7.2-fpm only working on IP Adressnginx 和 php7.2-fpm 仅适用于 IP 地址
【发布时间】:2019-01-19 03:14:58
【问题描述】:

我的 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 中工作 不知道为什么,谁能帮帮我?

【问题讨论】:

  • 所以在default.conf 中你有fastcgi_passphp7.2-fpm.sock 但另一个你把它设置为一个静态网站,因此它只有在通过IP 访问时才有效

标签: php nginx


【解决方案1】:

nginxwordpress codex 为例

    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$ 的第二个位置块将运行,它将所有带有php 文件扩展名的请求发送到php7.2-fpm.sock

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

【讨论】:

    猜你喜欢
    • 2014-09-27
    • 1970-01-01
    • 2021-07-30
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 2019-07-17
    • 1970-01-01
    相关资源
    最近更新 更多