【发布时间】: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