dongtu1357 2019-01-18 18:29
浏览 250

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

Php Scripts on my Nginx / php7.2-fpm only working with the default config and the IP Adress not with Domain Names or subdomains...

My Configs:

Default Config

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;
    }

}

My Domain Config:

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/*;
}

Without that subdomain and with IP it works in /var/www/html Dont know why, can any1 Help me?

  • 写回答

1条回答 默认 最新

  • duanba5777 2019-01-18 19:14
    关注

    Using wordpress codex for nginx as an example

        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;
        }
    

    Which means for any request in this server block the first location block most likely will run. It will first try to find a static file, then try to look for a directory with that request path, then finally send it to index.php. When sent to the index.php the second location block of location ~ \.php$ will run which will send all requests with the php file extension to the php7.2-fpm.sock

    You currently have 2 server blocks. One in Default Config and one in My Domain Config. You have server_name web.mydomain.com; in your custom conf which means any requests to that host will be answered by that server block. Any other host will be handled by the Default Config which includes by IP.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘