GNU/Linux >> Belajar Linux >  >> Cent OS

Cara Mengatur Proksi Terbalik Nginx

Dalam tutorial ini, kami akan menunjukkan kepada Anda cara mengatur proxy terbalik. Bagi Anda yang belum tahu, proxy terbalik HTTPS Nginx adalah layanan proxy perantara yang mengambil klien permintaan, meneruskannya ke satu atau lebih server, dan kemudian mengirimkan respons server kembali ke klien. Jika Anda memiliki beberapa server, proxy terbalik dapat membantu menyeimbangkan beban antar server dan meningkatkan kinerja. Karena proxy terbalik menyediakan satu titik kontak untuk klien, ini dapat memusatkan pencatatan dan pelaporan di beberapa server.

Artikel ini mengasumsikan Anda memiliki setidaknya pengetahuan dasar tentang Linux, tahu cara menggunakan shell, dan yang terpenting, Anda meng-host situs Anda di VPS Anda sendiri. Instalasi cukup sederhana dan mengasumsikan Anda sedang berjalan di akun root, jika tidak, Anda mungkin perlu menambahkan 'sudo ' ke perintah untuk mendapatkan hak akses root. Saya akan menunjukkan kepada Anda langkah demi langkah untuk menyiapkan proxy terbalik.

Prasyarat

  • Server yang menjalankan salah satu sistem operasi berikut:CentOS atau Ubuntu Linux.
  • Sebaiknya Anda menggunakan penginstalan OS baru untuk mencegah potensi masalah.
  • Seorang non-root sudo user atau akses ke root user . Kami merekomendasikan untuk bertindak sebagai non-root sudo user , namun, karena Anda dapat membahayakan sistem jika tidak berhati-hati saat bertindak sebagai root.

Mengatur Proksi Terbalik Nginx

Langkah 1. Pertama, mari kita mulai dengan memastikan sistem Anda mutakhir.

sudo dnf update

Langkah 2. Menginstal Nginx di sistem Linux.

  • Menginstal Nginx di CentOS 8 semudah mengetik:
sudo dnf install nginx
  • Menginstal Nginx di Ubuntu 20.04 LTS semudah mengetik:
sudo apt install nginx

Setelah penginstalan selesai, aktifkan dan mulai layanan Nginx:

sudo systemctl enable nginx
sudo systemctl start nginx

Navigasi ke http://localhost di browser Anda untuk memverifikasi bahwa server web berjalan seperti yang diharapkan:

Langkah 3. Siapkan Proksi Terbalik Nginx.

Pertama, ikuti perintah di bawah ini untuk menonaktifkan virtual host:

sudo unlink /etc/nginx/sites-enabled/default

Kita perlu membuat file di dalam /etc/nginx/sites-available direktori yang berisi informasi proxy terbalik. Kita dapat menamai ini reverse-proxy.conf misalnya:

nano reverse-proxy.conf
server {
    listen 80;
    location / {
        proxy_pass http://192.168.77.20;
    }
}

Bagian penting di sini adalah proxy_pass direktif yang pada dasarnya memberi tahu setiap permintaan yang datang melalui proxy terbalik Nginx untuk diteruskan ke soket jarak jauh Apache 192.168.77.20:80.

Setelah Anda menambahkan arahan yang sesuai ke .conf Anda file, aktifkan dengan menautkan ke /sites-enabled/ menggunakan perintah berikut:

ln -s /etc/nginx/sites-available/reverse-proxy.conf /etc/nginx/sites-enabled/reverse-proxy.conf

Uji file konfigurasi Nginx:

$ sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Terakhir, kita perlu menjalankan tes konfigurasi Nginx dan memulai ulang Nginx untuk memeriksa kinerjanya:

sudo systemctl restart nginx

Langkah 4. Nginx Reverse Proxy menggunakan Let's Encrypt.

Jalankan perintah ini pada baris perintah pada mesin untuk menginstal Certbot:

wget https://dl.eff.org/certbot-auto
sudo mv certbot-auto /usr/local/bin/certbot-auto
sudo chown root /usr/local/bin/certbot-auto
sudo chmod 0755 /usr/local/bin/certbot-auto

Kemudian, jalankan perintah ini untuk mendapatkan sertifikat dan minta Certbot mengedit konfigurasi Nginx Anda secara otomatis:

sudo /usr/local/bin/certbot-auto --nginx

Hasilnya seperti di bawah ini:

Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: your-domain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for your-domain-a.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/reverse-proxy.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/reverse-proxy.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://your-domain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=your-domain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/your-domain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/your-domain.com/privkey.pem
   Your cert will expire on 2020-08-03. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Selamat! Anda telah berhasil menyiapkan proxy terbalik. Terima kasih telah menggunakan tutorial ini untuk menyiapkan Nginx Reverse Proxy di sistem Linux. Untuk bantuan tambahan atau informasi berguna, kami sarankan Anda memeriksa situs web resmi Nginx.


Cent OS
  1. Cara menginstal Odoo 11 di CentOS 7 dengan Nginx sebagai Proxy Terbalik

  2. Cara Menginstal Flectra di CentOS 8 dengan Nginx sebagai Proxy Terbalik

  3. Cara Menginstal Odoo 14 di CentOS 8 dengan Nginx sebagai Reverse Proxy

  1. Cara Mengatur Proksi Terbalik Nginx

  2. Reverse Proxy dengan Nginx:Panduan Pengaturan Langkah-demi-Langkah

  3. Cara Mengatur Nginx sebagai Proxy Terbalik di Ubuntu 20.04

  1. Cara Menginstal Odoo 10 di CentOS 7 dengan Nginx sebagai Proxy Terbalik

  2. Cara Menginstal Flectra di Ubuntu 20.04 dengan Nginx sebagai Proxy Terbalik

  3. Cara Menginstal Odoo 12 di Ubuntu 18.04 dengan Nginx sebagai Proxy Terbalik