Em vừa mới chuyển sang nginx nhưng lại không biết rewrite từ file .htaccess (Apache) sang conf (Nginx). bác nào rành vụ này giúp em với. Code: # Comment the 2 lines below if the server returns 500 errors! Options -Indexes Options +FollowSymLinks #Uncomment following lines if you want to use image caching! # # ExpiresActive On # ExpiresDefault A1209600 # ExpiresByType text/html A1 # # Uncomment following lines if Apache doesnt support MultiViews! RewriteEngine On # Uncomment the 2 lines below if you are using www.domain.com # as the baseurl for the site and users access your site # via domain.com (THIS IS REQUIRED FOR JQUERY TO WORK) RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* loader.php [L,QSA] # Edit below lines and set to # ErrorDocument CODE /RELATIVE/error.php # If the script is installed in the default document # root then relative is null. #ErrorDocument 401 /error.php #ErrorDocument 403 /error.php #ErrorDocument 404 /error.php
Vụ này hại não lắm, trên mạng có 1 số trang hỗ trợ convert sang nhưng phần đa lỗi. Phải tự tìm rồi làm lại từng đoạn code.
PHP: location / {if ($http_host ~* "^domain.com"){rewrite ^(.*)$ http://www.domain.com/$1 redirect;}if (!-e $request_filename){rewrite ^(.*)$ /loader.php break;}}
Edit default.conf: Code: # # The default server # server { listen 80; server_name 2-tek.org; #charset koi8-r; #access_log logs/host.access.log main; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /usr/share/nginx/html; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$uri&$args; } location /internal_data/ { internal; } location /library/ { internal; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/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 /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { expires 365d; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } Nhiu đó đủ rồi! Cứ xem 2-tek cùa mình ! Nhớ xóa hết các file .htaccess đi nhé!