LoginSignup
4
6

More than 3 years have passed since last update.

RaspberryPiを無線Webサーバにする(nginx)

Last updated at Posted at 2017-12-15

経緯

保護猫を引き取り、初めて猫との共同生活をしています。
平日は帰宅の時間が遅いので、仕事の間猫がどうしているか心配でならず..

市販のペット監視ソリューションを見ていたのですが、
いい値段がしたので購入に踏み切れず..
それならば、自分がラズベリーパイでサーバ立てて、カメラ(¥1000)を設置したら
安くで作れるんじゃないかなと思い、トライしてみた次第であります。

ラズパイを無線サーバにする迄

ラズパイの組み立て方はここには載ってませんので悪しからず。

◆前提条件
下記サイトにて、イメージを落としてくる。
https://www.raspberrypi.org/downloads/raspbian/

1.イメージの作成

diskutil list
diskutil eraseDisk FAT32 NEKOBERRY /dev/disk4
diskutil unmountDisk /dev/disk4
cd /Users/[ユーザ名]/Downloads
sudo dd bs=1m if=2017-09-07-raspbian-stretch-lite.img of=/dev/rdisk4
cd /Volumes/boot/
touch ssh

2.RaspberryPiへの接続(まずは有線で)

ssh pi@IPアドレス
sudo apt-get update
sudo apt-get upgrade

3.RaspberryPiの設定

sudo raspi-config

hostname(3)を選択後、名前を変更
localazation option:(4)を選択後以下を変更
change local:ja-UTF8を選択
change timezome:Tokyoを選択

4.無線LANでの接続設定

sudo apt-get install vim
sudo update-alternatives —config editor
「/usr/bin/vim.basic」を選択
cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.bk
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf

# Wi-FiのIDとPWを入力
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="YOUR_WIFI_SSID"
    psk="YOUR_WIFI_PASSWORD"
    key_mgmt=WPA-PSK
}
sudo reboot
ifconfig # IPアドレスを確認

5.確認

別途、同じWiFiに接続した Macでターミナルを起動し、SSH接続。以下のメッセージが出たらOK。
ssh pi@IPアドレス

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Nov 18 17:21:24 2017 from [IPアドレス]
SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

6.IPアドレスを固定する

sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bk
sudo vi /etc/dhcpcd.conf

#追記
interface wlan0
static ip_address=192.168.0.100/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

sudo reboot #再起動
sudo shutdown -h now #シャットダウン

7.nginxのインストール

sudo apt-get install nginx
sudo /etc/init.d/nginx start

ラズパイ、前々から気になってました。
今も家で地味に動いてます。
家にサーバがあるってなんかweb屋さんぽいです。。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6