Nginx下 怎么开启 Url重写

php中文网
发布: 2016-06-23 14:23:31
原创
1125人浏览过

本帖最后由 yxqc 于 2013-10-07 11:58:51 编辑

我的Nginx.conf如下:
#user  nobody;worker_processes  1;error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '    #                  '$status $body_bytes_sent "$http_referer" '    #                  '"$http_user_agent" "$http_x_forwarded_for"';    #access_log  logs/access.log  main;    sendfile        on;    #tcp_nopush     on;    #keepalive_timeout  0;    keepalive_timeout  65;    #gzip  on;    server {        listen       8088;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            root   D:/CwsServ/www;            index  index.php index.html index.htm ;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }        # proxy the PHP scripts to Apache listening on 127.0.0.1:80        #        #location ~ \.php$ {        #    proxy_pass   http://127.0.0.1;        #}        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        location ~ \.php {            root           D:/CwsServ/www;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  D:/CwsServ/www$fastcgi_script_name;            include        fastcgi_params;						#pathinfo support             set $real_script_name $fastcgi_script_name;             set $path_info "";             if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$")			{                 set $real_script_name $1;                 set $path_info $2;             }               fastcgi_param SCRIPT_NAME $real_script_name;             fastcgi_param PATH_INFO $path_info;         }        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}    # HTTPS server    #    #server {    #    listen       443;    #    server_name  localhost;    #    ssl                  on;    #    ssl_certificate      cert.pem;    #    ssl_certificate_key  cert.key;    #    ssl_session_timeout  5m;    #    ssl_protocols  SSLv2 SSLv3 TLSv1;    #    ssl_ciphers  HIGH:!aNULL:!MD5;    #    ssl_prefer_server_ciphers   on;    #    location / {    #        root   html;    #        index  index.html index.htm;    #    }    #}}
登录后复制

回复讨论(解决方案)

http://wiki.nginx.org/HttpRewriteModule

nginx的文档写得很全面了

http://wiki.nginx.org/HttpRewriteModule

nginx的文档写得很全面了

不知我的nginx.conf要怎么修改???

有人知道不?

编译时不指定--without-http_rewrite_module默认就是开启的。


使用rewrite指令来完成url重写,rewrite指令只适用于server、location和if域中,其它域中不支持。


例子:

server{
        listen       80;
        server_name test.angryfrog.com;
        root /Users/angryfrog/website/test;
        index index.php;
        
        if (!-f $request_filename){
            rewrite ^/(.+)$ /index.php?$1& last;
        }
}

此站点下请求的如果请求的文件不存在,则将会重定向到根目录下得index.php文件,并将请求的内容作为参数传给index.php文件。

参考文章: nginx url重写-rewrite实例
nginx rewrite(nginx url地址重写)的配置示例
超详细的 NGINX URL重写实例讲解

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号