我正在尝试在NGINX中使用url重写,但它不起作用。目前我正在使用IP地址访问该网站。
重写^ / mytest /(.*)?。html $ /mytest.html?$ 1 last;
然而,当我添加绝对URL时,它确实如此。
重写^ / mytest /(.*)?。html $ http://xx.xxx.xxx.xxx/mytest.html?$ 1 last;
我想使用相对网址,以便网址不会更改并保持不变。
整个nginx配置......
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
index index.php index.html index.htm;
server {
listen 80;
server_name xx.xxx.xxx.xxx;
root /export/www/mysite/htdocs;
rewrite ^/mytest/(.*)?.html$ mytest.html?$1 last;
location / {
index index.php index.html index.htm;
if (!-e $request_filename) { rewrite ^(.+)$ /index.php last; }
try_files $uri $uri/ index.php;
}
error_page 404 /404.html;
location = /40x.html {
}
location ~ \.php$ {
root /export/www/mysite/htdocs;
proxy_pass http://127.0.0.1;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/spool/phpfpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
try_files $uri $uri/ @handler;
expires off;
## Static conetnt cache
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
}
location /. { ## Disable .htaccess and other hidden files
return 404;
}
location @handler {
rewrite / /index.php;
}
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
location ~ .php$ {
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass unix:/var/spool/phpfpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
}
}