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

版权声明:本文为博主原创文章,转载请标注出处,谢谢。 https://blog.csdn.net/qq_33182756/article/details/80757107

想要的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;



猜你喜欢

转载自blog.csdn.net/qq_33182756/article/details/80757107