更新時間:2021-12-17 13:05:01 來源:動力節(jié)點 瀏覽9582次
在nginx中使用偽靜態(tài)直接在nginx中寫規(guī)則。conf,并且不需要像apache這樣的偽靜態(tài)操作來啟用寫模塊(mod_rewrite)。
1.Nginx只需要打開nginx即可。conf 配置文件并在服務器中寫入所需的規(guī)則。
代碼如下:
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;
}
下面是偽靜態(tài)
Location /{
Rewrite ^ (. *)/equip(d00000000.html $1/index.php?M = content & c = index & a = lists & catid = $2 last;
}
Access_log off;
}
然后重啟nginx服務器,偽靜態(tài)就會生效。這個維護不方便我們寫在一個外部文件中,比如bbs_nginx.conf。
保存代碼
代碼如下:
Location /{
Rewrite ^ (. *)/equip(d00000000.html $1/index.php? M = content & c = index & a = lists & catid = $2 last;
}
然后我們在上面的代碼root/home/www/bbs中加入如下代碼:
代碼如下:
包含/home/www/bbs/bbs_nginx.conf;
包含網(wǎng)站根目錄下的bbs_nginx.conf偽靜態(tài)規(guī)則,可以單獨管理..
重啟阿帕奇。
創(chuàng)建一個。.htaccess 文件的目錄中。htaccess 文件,
例如,在我的 Discuz 論壇目錄中:
代碼如下:
Vim/var/www/html/168 pc/bbs/. 訪問
2. 在其中輸入規(guī)則。這里我輸入Discuz的偽靜態(tài)規(guī)則(這里只添加了Discuz的偽靜態(tài)規(guī)則):
代碼如下:
# 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 被保存并退出。
3.修改nginx配置文件:
代碼如下:
Vim/etc/nginx.conf 配置文件
4. 介紹。htaccess 文件到需要添加偽靜態(tài)主機的虛擬主機的服務器 {},
代碼如下:
包括/var/www/html/168 pc/bbs/。htaccess ;(
將此更改為您的特定位置。htaccess 文件)
Wq 被保存并退出。
5.重新加載nginx配置文件:
代碼如下:
/Etc/init. d/nginx reload
以上就是Nginx偽靜態(tài)的配置方法,相信大家已經有所了解,如果您想了解更多相關知識,可以關注動力節(jié)點的Java視頻教程,教程內容全面,通俗易懂,適合沒有基礎的朋友學習,希望對大家能夠有所幫助。