Redirect http sang https nginx như thế nào?

Thảo luận trong 'VPS | Hosting Linux / Windows' bắt đầu bởi seolagi, 9/10/23.

  1. seolagi
    Tham gia ngày:
    16/4/14
    Bài viết:
    1,030
    Đã được thích:
    81
    Điểm thành tích:
    48
    Cho em hỏi làm sao để redirect http sang https nginx vậy cả nhà, bình thường server apache thì làm dễ dàng, sao qua cái server Nginx nó khó quá, tìm hiểu trên mạng mà không thể làm được hizzz.
    Bạn nào biết cách redirect http sang https trên server nginx giúp em cái, cảm ơn.

    FIle nginx.conf (bạn Minh đưa trong chát cho admin, chèn vào đây cho mọi người xem)
    Mã:
    server
    {
        listen 103.57.220.117:80;
        server_name itseovn.com www.itseovn.com ;
        access_log /var/log/nginx/domains/itseovn.com.log;
        access_log /var/log/nginx/domains/itseovn.com.bytes bytes;
        error_log /var/log/nginx/domains/itseovn.com.error.log;
        root /home/e2nvy/domains/itseovn.com/public_html;
        index index.php index.html index.htm;
        include /usr/local/directadmin/data/users/e2nvy/nginx_php.conf;
        include /etc/nginx/webapps.conf;
        location / {
                    try_files $uri $uri/ /index.php?$args;
                    }
    }
    
    server
    {
        listen 103.57.220.117:443 ssl http2;
        server_name itseovn.com www.itseovn.com ;
        access_log /var/log/nginx/domains/itseovn.com.log;
        access_log /var/log/nginx/domains/itseovn.com.bytes bytes;
        error_log /var/log/nginx/domains/itseovn.com.error.log;
        root /home/e2nvy/domains/itseovn.com/private_html;
        index index.php index.html index.htm;
        ssl_certificate /usr/local/directadmin/data/users/e2nvy/domains/itseovn.com.cert.combined;
        ssl_certificate_key /usr/local/directadmin/data/users/e2nvy/domains/itseovn.com.key;
        include /usr/local/directadmin/data/users/e2nvy/nginx_php.conf;
        include /etc/nginx/webapps.ssl.conf;
        location / {
                    try_files $uri $uri/ /index.php?$args;
                    }
    }
     
    Cảm ơn đã xem bài:

    Redirect http sang https nginx như thế nào?

    Last edited by a moderator: 9/10/23
  2. admin
    Tham gia ngày:
    22/5/13
    Bài viết:
    4,909
    Đã được thích:
    1,201
    Điểm thành tích:
    113
    Giới tính:
    Nam
    Của bạn đang sử dụng DirectAdmin thì có 2 cách sau:

    Cách 1: xử lý trên trình duyệt DirectAdmin


    Bạn dùng cách này đơn giản xử lý trên trình duyệt của DirectAdmin có sẵn cho phép người dùng thao tác nhé.

    Xem video chi tiết cách ở dưới đây.


    Cách 2: xử lý trực tiếp trên VPS


    Bạn truy cập vào đường dẫn sau để chỉnh sửa file:

    Bước 1:
    • /usr/local/directadmin/data/users/tên_user_web_của_bạn/nginx.conf (Với 1 số hệ điều hành khác thì vào: /etc/nginx/tên_website_của_bạn/server.conf, /etc/nginx/nginx.conf, /usr/local/nginx/conf hoặc /usr/local/etc/nginx).
    • Mở file trên lên thêm code sau vào đoạn listen 80:
    Mã:
    return 301 https://$host$request_uri;
    (Tùy vào mỗi VPS sử dụng hệ điều hành khác nhau mà đoạn này bên trong mặc định hiện thì 1 cách khác nhau, cơ bản là tìm tới dòng có chữ listen 80 để thêm nhé)

    Bước 2:
    • Xong lưu lại, và chạy lại nginx bằng lệnh sau: # sudo service nginx restart
    redirect-http-to-https-nginx-1.jpg
     
    Chỉnh sửa cuối: 3/11/23


Chủ để tương tự : Redirect http
Diễn đàn Tiêu đề Date
VPS | Hosting Linux / Windows Cài đặt Redirect www.subdomain to subdomain trên quản lý DNS như thế nào 6/1/20