我使用以下配置监听端口80,但重定向到https。然后,为了通过index.php文件路由所有内容,当我转到一个页面时,它只是下载index.php文件或在主页上显示403 forbidden。
有什么想法吗?
server {
    listen 80;
    server_name www.mydomain.com mydomain.com;
    rewrite ^ https://$server_name$request_uri? permanent;
}
server {
    listen 443;
    server_name www.mydomain.com;
    root /var/www/mydomain/public;
    ssl on;
    ssl_certificate mydomain.crt;
    ssl_certificate_key mydomain.key;
    ssl_session_timeout 5m;
    ssl_protocols SSLv3 TLSv1;
    ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
    ssl_prefer_server_ciphers on;
    location / {
        if (!-e $request_filename){
            rewrite \.(jpeg|jpg|gif|png)$ /public/404.php break;
        }
        if (!-e $request_filename){
            rewrite ^(.*)$ /index.php break;
        }
    }
    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index /index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_split_path_info       ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root /var/www/mydomain/public;
    }
    location ~ /\.ht {
        deny all;
    }
}发布于 2016-02-14 03:37:17
rewrite/break使重写的URI在相同的位置(location /)而不是在location ~ \.php中处理。请参阅rewrite文档。
具有两个完全相同的if块的location /块看起来相当奇怪。
您可以考虑将其拆分为两个块:
location / {
    try_files $uri /index.php;
}
location ~ \.(jpeg|jpg|gif|png)$ {
    try_files $uri /public/404.php;
}如果/public/404.php是所有404错误的默认处理程序,则可以使用error_page指令:
error_page 404 /public/404.php;
location / {
    try_files $uri /index.php;
}
location ~ \.(jpeg|jpg|gif|png)$ {
    try_files $uri =404;
}有关更多信息,请参阅location、try_files和error_page文档。
https://stackoverflow.com/questions/35382882
复制相似问题