---
title: "Nginx和Apache伪静态配置"
author: "wangking717"
date: "2016-05-10T17:24:40Z"
tags: []
categories: ["企业架构"]
slug: "nginx-apache"
draft: false
lastmod: "2016-05-11T16:22:26Z"
id: 2297244
url: "https://wangking717.iteye.com/blog/2297244"
---

很多程序都会用到伪静态。在这里统一记录下操作的方法。

 

**Apache伪静态配置：**  
A) PHP配置

```
vim /etc/php.ini
cgi.fix_pathinfo = 1 #将注释去掉
```

 

B) apache配置

```
vim /etc/httpd/conf/httpd.conf
LoadModule rewrite_module modules/mod_rewrite.so #将该句注解去掉。
<Directory />
  Options FollowSymLinks
  AllowOverride None  
</Directory>
#中把AllowOverride的None改为All
service httpd restart #重启apache
```

 

**Nginx伪静态配置**

```
vim /etc/nginx/conf.d/default.conf

location / {
        root /var/www/html;
        index index.html index.htm index.php;
}

#在这里面加入各自程序的伪静态规则，如thinkphp的伪静态规则如下

location / {
        root /var/www/html;
        index index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=$1  last;
            break;
        }
}

service nginx restart #重启nginx
```

 

按照这样的方式，伪静态就生效了！