简体   繁体   English

在Nginx上使用index.html的WordPress(Debian)

[英]Wordpress with index.html on nginx (debian)

I have a server with nginx (php-fpm), but I need the index to be index.html. 我有一台具有nginx的服务器(php-fpm),但我需要将索引设置为index.html。

My configuration is this: 我的配置是这样的:

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

By having this, only the index.html works, but nothing with php, and by removing the location's index.html, everything works fine with php, but not the index.html 这样,只有index.html可以工作,而php则没有任何作用,并且删除位置的index.html,一切都可以在php上正常工作,而index.html却没有

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

Do you know how I can do it so that both cases work? 您知道我该怎么做才能使两种情况都起作用吗?

(index.html and dynamic pages with php like mysite.com/tag/my-tag) (index.html和带有php的动态页面(如mysite.com/tag/my-tag))

I hope I have explained well. 我希望我解释得很好。

Using /index.html as the first parameter to try_files will break things. 使用/index.html作为try_files的第一个参数会破坏事情。

The index directive will look for matching files in the order presented. index指令将按照显示的顺序查找匹配的文件。 See this document for details. 有关详细信息,请参见此文档

So if you have a directory containing more than one type of index file, simply construct your index statement in the order you would like Nginx to prioritise them. 因此,如果您的目录包含多种类型的索引文件,只需按照您希望Nginx对其进行优先排序的顺序来构造index语句。

For example: 例如:

index index.html index.php;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM