nginx url重寫

來源:互聯網
上載者:User

標籤:

 

[[email protected] www]# cat /app/server/nginx/conf/vhosts/default.confserver {    listen 80 default_server;    server_name localhost;    root /app/www;    index index.php index.htm index.html;    rewrite /last.html /index.html last;    rewrite /break.html /index.html break;    rewrite /redirect.html /index.html redirect;#302臨時重新導向    rewrite /permanent.html /index.html permanent;#301永久重新導向    rewrite ^/html/(.+?).html$ /post/$1.html permanent;    location ~ .*\.(php|php5)?$    {       #fastcgi_pass  unix:/tmp/php-cgi.sock;        fastcgi_pass  127.0.0.1:9000;    fastcgi_index index.php;    include fastcgi.conf;    }    access_log  /app/log/nginx/access/default.log;}[[email protected] www]# tree /app/www//app/www/├── index.html├── index.php└── post    └── test.html1 directory, 3 files[[email protected] www]# cat /app/www/index.html [email protected]163.com[[email protected] www]# cat /app/www/post/test.html post/test.html

 

[[email protected] www]# curl 192.168.1.24/last.html[email protected]163.com[[email protected] www]# curl --head 192.168.1.24/last.htmlHTTP/1.1 200 OKServer: nginx/1.4.4Date: Tue, 02 Aug 2016 01:53:10 GMTContent-Type: text/htmlContent-Length: 16Last-Modified: Mon, 18 Jul 2016 11:46:03 GMTConnection: keep-aliveETag: "578cc17b-10"Accept-Ranges: bytes
[[email protected] www]# curl 192.168.1.24/break.html[email protected]163.com[[email protected] www]# curl --head 192.168.1.24/break.htmlHTTP/1.1 200 OKServer: nginx/1.4.4Date: Tue, 02 Aug 2016 01:54:40 GMTContent-Type: text/htmlContent-Length: 16Last-Modified: Mon, 18 Jul 2016 11:46:03 GMTConnection: keep-aliveETag: "578cc17b-10"Accept-Ranges: bytes
[[email protected] www]# curl 192.168.1.24/redirect.html<html><head><title>302 Found</title></head><body bgcolor="white"><center><h1>302 Found</h1></center><hr><center>nginx/1.4.4</center></body></html>

[[email protected] www]# curl 192.168.1.24/permanent.html<html><head><title>301 Moved Permanently</title></head><body bgcolor="white"><center><h1>301 Moved Permanently</h1></center><hr><center>nginx/1.4.4</center></body></html>

[[email protected] www]# curl 192.168.1.24/html/test.html<html><head><title>301 Moved Permanently</title></head><body bgcolor="white"><center><h1>301 Moved Permanently</h1></center><hr><center>nginx/1.4.4</center></body></html>

 注意:因為301和302不能簡單的只返回狀態代碼,還必須有重新導向的URL,這就是return指令無法返回301,302的原因了;

nginx url重寫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.