• Home
  • Chuyên mục
    • Hạt giống tâm hồn
      • Hạt giống tuổi trẻ
      • Hạt giống tình yêu
    • Tản mạn
      • Uncategorized
      • Linh tinh
    • Lập trình – Hệ thống
      • Thủ thuật
      • Linux
      • PHP
        • Drupal
        • wordpress
      • Python
    • Truyện
      • Truyện ngắn
    • Linh tinh
    • Tản mạn
  • Quyên góp/Donate
  • Liên hệ
Home » Lập trình » Cài đặt nginx và php-fpm ở 2 server khác nhau

Cài đặt nginx và php-fpm ở 2 server khác nhau

13/04/2018  Comment  

Hướng dẫn setup nginx và php-fpm được đặt ở 2 server khác nhau. Hoặc cụm server có private IP như digital ocean hoặc Amazon Web Service

Trong bài viết này, mình sử dụng 2 server ubuntu và có kết nối qua LAN IP ( private IP ), 2 server đã được mở port LAN.

Server chứa Nginx được gọi là server A với IP: 192.168.0.1, server chứa php-fpm được gọi là server B với IP 192.168.0.2.

Cả 2 server đã được cài đặt nginx và php-fpm để sẵn sàng.

Cấu hình php-fpm: /etc/php/7.2/fpm/pool.d/www.conf

[code]
; chuyển từ unix sang tcp/ip
listen = 9000
; cho phép các ip được kết nối với php-fpm
listen.allowed_clients = 127.0.0.1,192.168.0.1,192.168.0.2
[/code]

Restart lại php-fpm

[code]
sudo /etc/init.d/php7.2-fpm restart
[/code]

Cấu hình nginx: /etc/nginx/sites-available/demo.dungnt.net.conf

[code]
server {
listen 80;
listen [::]:80;

server_name demo.dungnt.net.conf;

#access_log /var/log/nginx/access_log.log;
#error_log /var/log/nginx/error_log.log;

root /var/www/demo.dungnt.net;
index index.html index.htm index.php;

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 192.168.0.2:9000;
}

location ~/\.ht {
deny all;
}
}
[/code]

Check nginx config

[code]
sudo nginx -t
[/code]

Restart nginx config

[code]
sudo nginx -s reload
[/code]

Tuy nhiên chưa chạy được, do server B chỉ xử lý PHP. và mong muốn xử lý các file tĩnh trực tiếp từ nginx nên cần mount file từ server B sang server A.

server A: cần cài thêm gói sshfs để mount qua ssh

[code]
sudo apt install sshfs
[/code]

Sau đó mount thư mục chứa code ở server sang server A qua ssh

[code]
sshfs -o allow_other,default_permissions [email protected]:/var/www/demo.dungnt.net /var/www/demo.dungnt.net
[/code]

thư mục chứa code ở server B: [email protected]:/var/www/demo.dungnt.net
thư mục chứa code được mount ở server A: /var/www/demo.dungnt.net

All done. Vậy là có thể truy cập được rồi.

Share this:

  • Email
  • Facebook
  • Twitter
  • Tumblr
  • Pinterest
  • Pocket
  • Print

Related

Filed Under: Lập trình, Linux, PHP Tagged With: nginx, php-fpm, remote php-fpm

About nhymxu

hơi gầy, hơi nhạt, não cá vàng và thích tạp nham

Leave a Reply

avatar
avatar
  Subscribe  
Notify of

Recent Posts

  • MongoDB và chuyện xóa dữ liệu
  • Tôi 26
  • 2018-11-13
  • 2018-11-12
  • 2018-10-27
  • 2018-10-24
  • Cách tổ chức models và auto import trong python
  • Chàng trai, ngủ ngon và mai thức giấc nhé.
  • Mã giảm giá CellphoneS, voucher CellphoneS, khuyến mãi giảm giá tháng 07/2018
  • Mã giảm giá Tiki, voucher tiki, khuyến mãi giảm giá tháng 07/2018

Recent Comments

  • Nhok on Tôi 25
  • Nhok on 2018-04-30
  • Nhok on Chàng trai, ngủ ngon và mai thức giấc nhé.
  • Nhok on Tôi 26
  • TrungAZ on Hướng dẫn tùy chỉnh cài đặt Microsoft Office 2016 Professional Plus

Blogroll

  • Bàn Long
  • Big Heart
  • Facebook
  • Instagram
  • keybase GPG
  • Thanhnt's blog
  • Truyện 247
  • Valentine 2014
  • Xmas 2013
  • Xmas 2015

Categories

Copyright © 2019 · Made with ♥ by Dũng Nguyễn (nhymxu)

wpDiscuz
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.