如果域名前面没有 www,浏览器会下载 php 文件而不是在浏览器中加载它?

如果域名前面没有 www,浏览器会下载 php 文件而不是在浏览器中加载它?

有人能帮帮我吗?我以前从未遇到过这个问题。

server {
listen 80;
server_name litl.it www.litl.it;

index index.html index.php index.htm;


access_log /var/www/litl.it/logs/access_logs.log;
error_log /var/www/litl.it/logs/error_logs.log;
root /var/www/litl.it/public/;
error_page 401 401.html;
error_page 403 403.html;
error_page 404 404.html;
error_page 500 502 503 504 500.html;

location / {
        try_files $uri $uri/ /index.php?$args;
 }

# rewrite adminpanel to use https
rewrite ^/adminpanel(.*)$ https://$host$uri permanent;

# Add trailing slash to */wp-admin requests. Needed if wordpress is installed later
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
         expires 30d;
}

# Deny all attempts to access hidden files such as .htaccess, .htpasswd
location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
}

location ~ \.php$ {
        try_files index index.php $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
         }

}

答案1

工作正常,很可能是您的浏览器缓存存在问题,返回了缓存的 mime 类型。

注意两个请求如何返回text/html。

[root@box ~]# curl -I litl.it
HTTP/1.1 200 OK
Server: nginx/1.1.19
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.3.10-1ubuntu3.8
Set-Cookie: laravel_session=118tej413g1rkrbgm4ncpe8486; expires=Wed, 13-Nov-2013 13:16:06 GMT; path=/; HttpOnly
Set-Cookie: laravel_session=118tej413g1rkrbgm4ncpe8486; expires=Wed, 13-Nov-2013 13:16:06 GMT; path=/; httponly
Cache-Control: no-cache
Date: Wed, 13 Nov 2013 11:16:06 GMT

[root@box ~]# curl -I www.litl.it
HTTP/1.1 200 OK
Server: nginx/1.1.19
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.3.10-1ubuntu3.8
Set-Cookie: laravel_session=h3rqp9nnbdopsoscmjttr2m2j1; expires=Wed, 13-Nov-2013 13:16:14 GMT; path=/; HttpOnly
Set-Cookie: laravel_session=h3rqp9nnbdopsoscmjttr2m2j1; expires=Wed, 13-Nov-2013 13:16:14 GMT; path=/; httponly
Cache-Control: no-cache
Date: Wed, 13 Nov 2013 11:16:14 GMT

相关内容