• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Nginx下 怎么开启 Url重写

php 搞代码 4年前 (2022-01-23) 19次浏览 已收录 0个评论
文章目录[隐藏]

本帖最后由 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 / {         <strong>2本文来源gaodaima#com搞(代@码$网6</strong><pre>搞gaodaima代码

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重写实例讲解


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Nginx下 怎么开启 Url重写

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址