linux centos7 下Nginx服务器实现URL重写去掉index.php方法,跟Apache还是不一样的。

11 篇文章 0 订阅
2 篇文章 0 订阅

想要的URL :http://localhost/Admin/ 而自己的是http://localhost/index.php/Admin/

方法:

在nginx配置文件nginx.conf中添加:

location / {

  if ( !e $request_filename ) {

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

  }

}

切记:不可以出现两个location / {}、否则nginx服务器将启动不了;

否则报错如下:

systemctl status nginx.service -l

● nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
   Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2018-06-21 10:37:14 CST; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 28469 ExecStop=/etc/rc.d/init.d/nginx stop (code=exited, status=0/SUCCESS)
  Process: 19590 ExecReload=/etc/rc.d/init.d/nginx reload (code=exited, status=0/SUCCESS)
  Process: 28485 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
 Main PID: 27022 (code=exited, status=0/SUCCESS)


Jun 21 10:37:14 vm10-0-0-19.ksc.com systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
Jun 21 10:37:14 vm10-0-0-19.ksc.com nginx[28485]:
Starting nginx: nginx: [emerg] duplicate location "/" in /usr/local/nginx/conf/nginx.conf:74
Jun 21 10:37:14 vm10-0-0-19.ksc.com nginx[28485]: [FAILED]
Jun 21 10:37:14 vm10-0-0-19.ksc.com systemd[1]: nginx.service: control process exited, code=exited status=1
Jun 21 10:37:14 vm10-0-0-19.ksc.com systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
Jun 21 10:37:14 vm10-0-0-19.ksc.com systemd[1]: Unit nginx.service entered failed state.

Jun 21 10:37:14 vm10-0-0-19.ksc.com systemd[1]: nginx.service failed.

还有就是要开启URL_MODEL = 2;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值