The use of pseudo-static in nginx directly writes rules in nginx. conf, and does not require pseudo-static operations like apache to enable the write module (mod_rewrite).
Nginx only needs to open the nginx. conf configuration file and write the required rules in the server.
| The code is as follows: |
Copy code |
Server { Listen 80; Server_name bbs.o135.cn; Index index.html index.htm index. php; Root/home/www/bbs; Error_page 404/404 .htm; # configure the 404 error page Location ~ . *. (Php | php5 )? $ { # Fastcgi_pass unix:/tmp/php-cgi.sock; Fastcgi_pass 127.0.0.1: 9000; Fastcgi_index index. php; Fcinclude GI. conf; } # Below is the pseudo-static Location /{ Rewrite ^ (. *)/equip(d00000000.html $1/index. php? M = content & c = index & a = lists & catid = $2 last; } Access_log off; } |
Then restart the nginx server and the pseudo-static state will take effect. This maintenance is inconvenient for us to write it in an external file, such as bbs_nginx.conf.
Save the code
| The code is as follows: |
Copy code |
Location /{ Rewrite ^ (. *)/equip(d00000000.html $1/index. php? M = content & c = index & a = lists & catid = $2 last; } |
Then we add the following code to the above code root/home/www/bbs:
| The code is as follows: |
Copy code |
| Include/home/www/bbs/bbs_nginx.conf; |
# Including the bbs_nginx.conf pseudo-static rules in the root directory of the website, which can be managed separately ..
Restart apache.
Create a. htaccess file in the directory of the. htaccess file,
For example, in my Discuz Forum directory:
| The code is as follows: |
Copy code |
Vim/var/www/html/168 pc/bbs/. htaccess |
2. Enter a rule in it. Here I enter the pseudo-static rule of Discuz (here only the pseudo-static rule of Discuz is added ):
| The code is as follows: |
Copy code |
# Nginx rewrite rule Rewrite ^ (. *)/archiver/(fid | tid0000-0000w-00000000.html) $1/archiver/index. php? $2 last; Rewrite ^ (. *)/forum-(%0-9%%%%%-(%0-9%%%%%%.html $1/forumdisplay. php? Fid = $2 & page = $3 last; Rewrite ^ (. *)/thread-(%0-9%%%%%-(%0-9%%%%%%%%%%.html $1/viewthread. php? Tid = $2 & extra = page % 3D $4 & page = $3 last; Rewrite ^ (. *)/profile-(username | uid+-(.20.20..html $1/viewpro. php? $2 = $3 last; Rewrite ^ (. *)/space-(username | uid+-(.20.20..html $1/space. php? $2 = $3 last; Rewrite ^ (. *)/tag-(.20.20..html $1/tag. php? Name = $2 last; # End nginx rewrite rule |
Wq is saved and exited.
3. Modify the nginx configuration file:
| The code is as follows: |
Copy code |
Vim/etc/nginx. conf |
4. Introduce the. htaccess file to the server {} of the virtual host to which pseudo-static hosts need to be added,
| The code is as follows: |
Copy code |
| Include/var/www/html/168 pc/bbs/. htaccess ;( |
Change this to the specific location of your. htaccess file)
Wq is saved and exited.
5. Reload the nginx configuration file:
| The code is as follows: |
Copy code |
/Etc/init. d/nginx reload |