我已经在依赖.htaccess重写规则的子文件夹中安装了脚本 – 如果您在正确安装后访问脚本,它将redirect到您实际上不存在于服务器上的/login页面。 然而,这一切都在Apache上。 我想知道如何将下面的.htaccess规则转换为nginx,但也不会影响我们的网站在根目录中。
.htaccess读取…
Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php
该脚本在一个子文件夹中
/clp2/
所以我假设如果我做任何redirect的位置规则,它将需要指定子文件夹? 由于这个.htaccess文件显然是文件夹特定的,而不是networking特定的。
脚本的完整服务器path是
/var/www/vhosts/i-16852366/clp2
任何input的欢迎,我认为这是很容易,如果你知道你在做什么 – 我试过一个nginx重写器,但它不工作,显然不是特定于我需要它做重写规则的文件夹,所以我也需要一些指导。
这里是我目前的nginx.conf – 我假设它会在http块的某个地方?
user nginx; worker_processes 2; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; use epoll; } http { include /etc/nginx/mime.types; default_type application/octet-stream; server { location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php; } } location /phpMyAdmin{ root /usr/share; index index.php; } location ~ \.php$ { set $php_root $document_root; if ($request_uri ~* /phpMyAdmin) { set $php_root /usr/share; } fastcgi_pass unix:/tmp/fastcgi.socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $php_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } } log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; log_format backend '$http_x_forwarded_for - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent"'; access_log /var/log/nginx/access.log main; server_name_in_redirect off; server_tokens off; sendfile on; tcp_nopush off; keepalive_timeout 5; client_max_body_size 4m; client_body_buffer_size 256k; if_modified_since before; gzip on; gzip_http_version 1.0; gzip_vary on; gzip_comp_level 6; gzip_types text/plain text/xml text/css text/javascript application/xhtml+xml application/xml application/rss+xml application/atom_xml application/javascript application/x-javascript application/x-httpd-php; gzip_disable "MSIE [1-6]\."; proxy_cache_key "$scheme://$host$request_uri"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Remote-Addr $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Accept-Encoding ""; proxy_hide_header X-Pingback; proxy_hide_header Link; proxy_hide_header ETag; proxy_connect_timeout 5; proxy_send_timeout 10; proxy_read_timeout 120; proxy_cache_use_stale timeout invalid_header http_500 http_502 http_503 http_504; proxy_cache_lock on; proxy_cache_lock_timeout 5s; upstream backend { server unix:/var/run/nginx-backend.sock; } upstream phpfpm { server unix:/var/run/php-fpm.sock; } include /etc/nginx/conf.d/*.conf;
这是一个try_files
的工作:
location /clp2 { try_files $uri /clp2/index.php; location ~ \.php(?|$) { ... } }