【问题标题】:Wordpress with index.html on nginx (debian)nginx(debian)上带有 index.html 的 Wordpress
【发布时间】:2019-05-01 13:30:39
【问题描述】:

我有一个带有 nginx (php-fpm) 的服务器,但我需要索引为 index.html。

我的配置是这样的:

server { 
    listen 80 default_server;

    #SSL configuration listen *:443 ssl http2;

    ssl_certificate /path/to/my.dev.pem; 
    ssl_certificate_key /path/to/my-key.pem;    

    root /home/path/to/misite.dev; 
    index index.php index.html index.htm; 
    server_name misite.dev ;

    location / { 
        try_files index.html $uri/ /index.php?$args; 
    }
    location ~ \.php$ { 
        try_files $uri =404;    
        fastcgi_split_path_info ^(.+\.php)(/.+)$;   
        fastcgi_pass unix:/run/php/php7.1-fpm.sock; 
        fastcgi_index index.php;    
        include fastcgi.conf; 
    } 
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff)$ {     
        add_header Access-Control-Allow-Origin *;   
        add_header Cache-Control "public, max-age=31536000, immutable";     
        access_log off; 
        log_not_found off; 
    }
    location = /robots.txt { 
        access_log off; 
        log_not_found off; 
    }
    location ~ /\. { 
        deny all; 
        access_log off; 
        log_not_found off; 
    } 
}

有了这个,只有 index.html 有效,而 php 无效,并且通过删除位置的 index.html,一切都可以在 php 上正常工作,但不能在 index.html 上工作

location / {try_files -> index.html <- $ uri / /index.php?$args;}

你知道我该怎么做才能让这两种情况都有效吗?

(index.html 和带有 php 的动态页面,例如 mysite.com/tag/my-tag)

希望我已经解释清楚了。

【问题讨论】:

  • 尝试将try_files 放回try_files $uri $uri/ /index.php?$args; 并将您的index 指令更改为index index.html index.php;
  • 完美运行!谢谢!!

标签: php wordpress nginx debian nginx-config


【解决方案1】:

使用/index.html 作为try_files 的第一个参数会破坏事情。

index 指令将按照显示的顺序查找匹配的文件。详情请见this document

因此,如果您的目录包含不止一种类型的索引文件,只需按照您希望 Nginx 优先考虑它们的顺序构造您的 index 语句。

例如:

index index.html index.php;

【讨论】:

    猜你喜欢
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-21
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    相关资源
    最近更新 更多