Help Rewrite Apache sang Nginx

pdinh97qng

MasterCorporal
Tham gia
12/05/2015
Bài viết
229
Được Like
218
:eek: 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.:oops:

Mã:
# 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!
#<IfModule mod_expires.c>
#  ExpiresActive On
#  ExpiresDefault A1209600
#  ExpiresByType text/html A1
#</IfModule>

# Uncomment following lines if Apache doesnt support MultiViews!
<IfModule mod_rewrite.c>
    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]
</IfModule>

# 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
 
  • Like
Reactions: THB

tri78

Moderator
Thành viên BQT
Tham gia
13/05/2015
Bài viết
429
Được Like
327
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.
 
  • Like
Reactions: THB
V

vanphu113

Khách VNXF
:eek: 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.:oops:

Mã:
# 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!
#<IfModule mod_expires.c>
#  ExpiresActive On
#  ExpiresDefault A1209600
#  ExpiresByType text/html A1
#</IfModule>

# Uncomment following lines if Apache doesnt support MultiViews!
<IfModule mod_rewrite.c>
    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]
</IfModule>

# 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
PHP:
location / {
if ($http_host ~* "^domain.com"){
rewrite ^(.*)$ http://www.domain.com/$1 redirect;
}
if (!-e $request_filename){
rewrite ^(.*)$ /loader.php break;
}
}
 

tri78

Moderator
Thành viên BQT
Tham gia
13/05/2015
Bài viết
429
Được Like
327
PHP:
location / {
if ($http_host ~* "^domain.com"){
rewrite ^(.*)$ http://www.domain.com/$1 redirect;
}
if (!-e $request_filename){
rewrite ^(.*)$ /loader.php break;
}
}
Chưa đủ đâu, để chạy ok thì cái nginx.conf phải gần 1 trang A4
 

2-tek

MasterCorporal
Tham gia
27/06/2015
Bài viết
326
Được Like
278
Edit default.conf:

Mã:
#
# 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é!
 

tri78

Moderator
Thành viên BQT
Tham gia
13/05/2015
Bài viết
429
Được Like
327
Edit default.conf:

Mã:
#
# 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é!
Của mình nhiều hơn, chặn dải ip từ 1 file txt. chống F5, khóa thư mục bằng pass.... đủ cả :D
 
Người đăng Chủ đề tương tự Diễn đàn Trả lời Ngày đăng
nguyenchican Server Configuration and Hosting 2

Chủ đề tương tự


Hướng dẫn sử dụng

XenForo 1 XenForo 2
Translate by PVS

Dịch vụ XenForo của VNXF

Mobile/Zalo: 0906081284

Telegram: anhanhxf

Chỉ nhận web nội dung lành mạnh

Nhà Tài Trợ

Mút Xốp Không Gian
Mút Sofa Không Gian
Top Bottom