Help Rewrite Apache sang Nginx

Thảo luận trong 'Server Configuration and Hosting' bắt đầu bởi pdinh97qng, 06/09/2016.

  1. pdinh97qng

    pdinh97qng Thượng Đế

    Tham gia:
    12/05/2015
    Bài viết:
    235
    Đã được thích:
    210
    Điểm thành tích:
    43
    Giới tính:
    Nam
    :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!
    #
    #  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
    
     
    Bài viết mới
    Lỗi forum khi post bài
    Lỗi forum khi post bài bởi maxrena, 09/03/2020 lúc 16:27:15
    THB thích bài này.
  2. tri78

    tri78 Thượng Đế

    Tham gia:
    13/05/2015
    Bài viết:
    306
    Đã được thích:
    257
    Điểm thành tích:
    63
    Giới tính:
    Nam
    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.
     
    THB thích bài này.
  3. vanphu113

    vanphu113 Khách VNXF

    PHP:
    location / {
    if (
    $http_host ~* "^domain.com"){
    rewrite ^(.*)$ http://www.domain.com/$1 redirect;
    }
    if (!-
    e $request_filename){
    rewrite ^(.*)$ /loader.php break;
    }
    }
     
    pdinh97qng thích bài này.
  4. tri78

    tri78 Thượng Đế

    Tham gia:
    13/05/2015
    Bài viết:
    306
    Đã được thích:
    257
    Điểm thành tích:
    63
    Giới tính:
    Nam
    Chưa đủ đâu, để chạy ok thì cái nginx.conf phải gần 1 trang A4
     
  5. 2-tek

    2-tek Thượng Đế

    Tham gia:
    27/06/2015
    Bài viết:
    275
    Đã được thích:
    214
    Điểm thành tích:
    43
    Giới tính:
    Nam
    Nghề nghiệp:
    Designer
    Nơi ở:
    HCMC
    Web:
    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é!
     
    pdinh97qng thích bài này.
  6. tri78

    tri78 Thượng Đế

    Tham gia:
    13/05/2015
    Bài viết:
    306
    Đã được thích:
    257
    Điểm thành tích:
    63
    Giới tính:
    Nam
    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
     
    pdinh97qng thích bài này.
  7. pdinh97qng

    pdinh97qng Thượng Đế

    Tham gia:
    12/05/2015
    Bài viết:
    235
    Đã được thích:
    210
    Điểm thành tích:
    43
    Giới tính:
    Nam
    Cảm ơn các bácYes~~
     

Chia sẻ trang này