上以小节还有两个问题:
第一、假设真实存在这么一个文件: /sort/1.html ,根据之前的配置,我们是访问不到这个文件的。
第二、如果有适用过 apache的同学应该知道,apache 是可以通过 .htaccess 来给每个虚拟主机单独设置 伪静态的,这样一来,站长就可以根据自己的需求来设置伪静态规则,不需要我们系统管理员动手了,但是之前的方法,明显需要管理员来设置。
好,我们一次性解决这两个问题。
但是配置有点麻烦,我们一步步来
先把我们之前的伪静态注释掉,换成:
#rewrite /sort/(.*)\.html /1.php?id=$1 last;
try_files $uri $uri/ @wjt;
然后增加这样的配置
location @wjt {
include /usr/share/nginx/html/1/.htaccess;
}
然后增加这个【 .htaccess 】 文件,内容如下
rewrite ^/sort/(.*).html$ /1.php?id=$1 last;
完美解决
此时, 1.conf 的配置应该如下:
server {
listen 80;
server_name 1.runcpp.com;
rewrite ^(.*)$ https://$host$1 permanent;
location / {
root /usr/share/nginx/html/1;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/1;
}
}
server{
listen 443;
server_name 1.runcpp.com;
ssl on;
ssl_certificate /etc/nginx/key/1.runcpp.com-ca-bundle.crt;
ssl_certificate_key /etc/nginx/key/1.runcpp.com.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html/1;
index index.html;
#rewrite /sort/(.*)\.html /1.php?id=$1 last;
try_files $uri $uri/ @wjt;
}
location @wjt {
include /usr/share/nginx/html/1/.htaccess;
}
location ~ \.php$ {
root /usr/share/nginx/html/1;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/1$fastcgi_script_name;
include fastcgi_params;
}
}
- 本文固定链接: https://www.runcpp.com/?p=163
- 转载请注明: 快前端 于 快前端 网站发表