How to enable Url rewriting in Nginx? This post was last edited by yxqc at 11:58:51, January 7 ,.
My Nginx. conf is as follows:
#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; # } #}}
Reply to discussion (solution)
Http://wiki.nginx.org/HttpRewriteModule
Nginx documentation is well written
Http://wiki.nginx.org/HttpRewriteModule
Nginx documentation is well written
I don't know how to modify my nginx. conf ???
Does anyone know?
Do not specify at compile time -- without-http_rewrite_module is enabled by default.
The rewrite command is used to complete url rewriting. the rewrite command is only applicable to the server, location, and if domains, but not to other domains.
Example:
Server {
Listen 80;
Server_name test.angryfrog.com;
Root/Users/angryfrog/website/test;
Index. php;
If (! -F $ request_filename ){
Rewrite ^/(. +) $/index. php? $1 & last;
}
}
If the requested file does not exist in the site, the request will be redirected to the index. php file in the root directory, and the requested content will be passed to the index. php file as a parameter.
Reference: nginx url rewriting-rewrite instance
Nginx rewrite (nginx url address rewriting) configuration example
Detailed description of nginx url rewriting instances