php laravel伪静态,laravel如何设置nginx伪静态?

按照官网设置的直接不解析网页变成下载了,试了网上的很多版本也没用。

用的是LNMP一键安装环境。

我的vhost配置信息:

server

{

listen 80;

#listen [::]:80;

server_name domain.com;

index index.html index.htm index.php default.html default.htm default.php server.php;

root /home/wwwroot/domain.com/public;

#error_page 404 /404.html;

location / {

try_files $uri $uri/ /index.php?$query_string;

}

location ~ [^/]\.php(/|$)

{

# comment try_files $uri =404; to enable pathinfo

try_files $uri =404;

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

#include pathinfo.conf;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

access_log /home/wwwlogs/domain.log access;

}

回复内容:

按照官网设置的直接不解析网页变成下载了,试了网上的很多版本也没用。

用的是LNMP一键安装环境。

我的vhost配置信息:

server

{

listen 80;

#listen [::]:80;

server_name domain.com;

index index.html index.htm index.php default.html default.htm default.php server.php;

root /home/wwwroot/domain.com/public;

#error_page 404 /404.html;

location / {

try_files $uri $uri/ /index.php?$query_string;

}

location ~ [^/]\.php(/|$)

{

# comment try_files $uri =404; to enable pathinfo

try_files $uri =404;

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fastcgi.conf;

#include pathinfo.conf;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

access_log /home/wwwlogs/domain.log access;

}

我的配置是这样的:

server

{

listen 80;

server_name b.phodal.com;

index index.html index.htm index.php default.html default.htm default.php;

root /home/www/MK_iot/public;

include other.conf;

location ~ .*\.(php|php5)?$

{

try_files $uri =404;

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fcgi.conf;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

if (!-d $request_filename)

{

rewrite ^/(.+)/$ /$1 permanent;

}

# removes trailing "index" from all controllers

if ($request_uri ~* index/?$)

{

rewrite ^/(.*)/index/?$ /$1 permanent;

}

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap

if (!-e $request_filename)

{

rewrite ^/(.*)$ /index.php?/$1 last;

break;

}

access_log /home/wwwlogs/b.phodal.com.log b.phodal.com;

}

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,要使用 Laravel 伪静态,需要在 Apache 或 Nginx 中配置伪静态规则。以下是在 Apache 中配置的示例: 1. 打开 Apache 的配置文件 `httpd.conf`,取消注释 `mod_rewrite` 模块: ``` LoadModule rewrite_module modules/mod_rewrite.so ``` 2. 找到 `<Directory>` 标签,将 `AllowOverride` 属性设置为 `All`: ``` <Directory "/path/to/laravel/public"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ``` 3. 创建 `.htaccess` 文件,将以下代码复制进去: ``` <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule> ``` 4. 保存 `.htaccess` 文件并上传到 Laravel 项目的 `public` 目录下。 以上就是在 Apache 中配置 Laravel 伪静态的步骤。 如果你使用的是 Nginx,可以按照以下步骤配置: 1. 打开 Nginx 的配置文件 `nginx.conf`,找到 `server` 标签,添加以下代码: ``` location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ``` 2. 保存配置文件并重启 Nginx 服务。 以上就是在 Nginx 中配置 Laravel 伪静态的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值