A secure home gateway on the Raspberry Pi in four parts. Part two, setting up nginx on the Raspi

I have some very nifty devices lying around in my home:
  • A couple of computers
  • A very smart router with the Tomato firmware
  • A Raspberry Pi model B (the only one you can get right now)
  • A Popcorn Hour A200
Besides that, I have full control over a domain name (waleson.com.).

The amount of cool things you can do with this is enormous. However, until yesterday morning, these devices were working with most of their default settings (BOOOORING). Here's how I made it awesome in one evening.

Part two, nginx on the Raspberry Pi.

  1. Part one - Dynamic DNS
Objective: You want to access the devices inside from outside over the internet. 

Naturally any other linux machine will do, but I have a Raspi lying around. It is energy efficient and fun to play with. Also, the Raspberry Pi is hot on the web, so it does wonders for your Hacker News article or your SEO leads. So if you don't have a Raspberry Pi, please do the substitution to whatever you have yourself, in your head.

I take it you have set-up Debian on a Raspberry Pi. Please use ssh keys as well: http://raspberrypi.stackexchange.com/questions/1686/how-do-i-set-up-ssh-keys-to-log-into-my-rpi

Connect your Raspberry Pi to the network. In your router, assign a static IP lease to the raspberry pi. That is, each time the raspberry connects to the network, the DHCP server in the router will assign it the same IP. Then, still in your router, forward ports 80 and 443 to the IP of the raspberry pi. Now all incoming traffic to your domain name on port 80 (http://) and 443 (https://) will be handled by the raspberry pi. However it does not listen on those ports yet. We need to set up a web server: nginx. Why not apache? Nginx is simpler, faster and most important on the Raspi: it has a low memory profile.

The process is rather simple. Set up nginx (all commands prefixed with sudo, or run as root):
apt-get update
apt-get install nginx
Your /etc/nginx/nginx.conf file is good to go out of the box. Do this:
cd /etc/nginx
YOUR_EDITOR sites-available/YOUR_DOMAIN.conf
in my case I substitued YOUR_EDITOR for vim, and YOUR_DOMAIN for home.waleson.com. Put this in the file:
server {
        server_name YOUR_DOMAIN;
        listen 80;
        error_log /var/log/nginx/home.error;
        access_log /var/log/nginx/home.access;
        root /srv/www;
        index index.html /index.html;
}
restart nginx:
/etc/init.d/nginx restart

Create a /srv/www directory and put an index.html file in there.

Try it! Go to http://YOUR_DOMAIN to see the index.html page!

Objective two accomplished!

Read on: part three - free HTTPS to the rescue

Comments

  1. Great tutorial!
    I am following along and wanted to point out a step that is different for me and may be different for other people as well.

    In addition to creating the new config file:
    vim /etc/nginxsites-available/YOUR_DOMAIN.conf

    The exsting symbolic link:
    /etc/nginx/sites-enabled/default
    which originally points to:
    /etc/nginx/sites-available/default
    must be changed to point to the new config file:
    /etc/nginx/sites-available/YOUR_DOMAIN.conf

    The commands to do this are the following:
    cd /etc/nginx/sites-enabled/
    sudo ln -s /etc/nginx/sites-available/YOUR_DOMAIN.conf
    sudo /etc/init.d/nginx restart

    ReplyDelete
  2. đồng tâm
    game mu
    cho thuê nhà trọ
    cho thuê phòng trọ
    nhac san cuc manh
    số điện thoại tư vấn pháp luật miễn phí
    văn phòng luật
    tổng đài tư vấn pháp luật
    dịch vụ thành lập công ty trọn gói
    lý thuyết trò chơi
    đức phật và nàng
    hồ sơ mật dinh độc lập
    đừng hoang tưởng về biển lớn
    chiến thắng trò chơi cuộc sống
    lượng tử
    ngồi khóc trên cây
    truy tìm ký ức
    mặt dày tâm đen
    thế giới như tôi thấy

    Tố nương thở nhẹ một tiếng, vẻ mặt thẹn thùng vô cùng, cả người vô lực nằm trong lòng hắn, đồn bộ chuyển động lên xuống nhẹ nhàng, sung sướng hưởng thụ cây bổng tráng kiện của nam nhân....
    Một lúc lâu sau, rốt cuộc hai người đi ra khỏi phòng với vẻ mặt thỏa mãn, có thể nhìn thấy rõ nét ửng hồng của cao trào còn chưa có rút đi.
    “Thiếu gia, người đưa đến đây mười nữ tử tư chất không tồi, rất có tiềm lực, phỏng chừng không đầy nửa năm là có thể có sức chiến đấu ngang ngửa với Phượng Vệ. Nếu có thể, ta hi vọng người có thể cung cấp thêm một ít nhân thủ nữa." Nữ nhân sau cơn mây mưa thì tâm hồn như được thức tỉnh, nàng hoàn toàn tin tưởng vào thiếu gia, người đem lại cho nàng nhiều hạnh phúc và kích tình, tất nhiên nàng sẽ hết lòng báo đáp.
    Lưu Phong nghe vậy trong lòng rất vui vẻ, có Tố Nương cùng Hắc Vân Bang thay mình huấn luyện thủ hạ, tương lai không lo thế lực của mình không thể mở rộng.
    “Tố nương tỷ tỷ, ngươi yên tâm, qua mấy ngày nữa ta sẽ chọn lựa thêm mấy người đưa cho nàng.” Lưu Phong quyết định qua mấy ngày nữa công việc xong xuôi phải làm việc này, phải tìm những thanh thiếu niên, những cô gái gặp hoàn cảnh khó khăn mang về đem giao cho Tố Nương huấn luyện.
    “ Thiếu gia người cứ mang người về, ta sẽ huấn luyện những người này “ Tố Nương ôn nhu nói.
    “ Tố Nương tỷ tỷ, sau này nếu muốn tới tìm ta, nàng cứ đến đừng ngại ngùng,……..” Lưu Phong nói lời này có hai nghĩa, việc công, việc tư, dù sao chỉ cần có việc ngươi hãy cứ đến.
    Tố Nương nhẹ dạ một tiếng, có chút thẹn thùng, dù sao thì cũng là nàng sau lưng mọi người có quan hệ lén lút với Lưu Phong, nói ra chỉ nhục nhã, vội vàng đi không hề quay đầu lại, nhưng trong lòng nàng lại cực kì cao hứng.
    Lưu Phong đưa mắt nhìn Tố Nương rời đi, đột nhiên nhớ tới lời Vương Đức Vọng nói, chẳng lẽ thật sự mình đang lợi dụng thân thể để làm việc hay sao?

    ReplyDelete

Post a Comment

Popular posts from this blog

The unreasonable effectiveness of i3, or: ten years of a boring desktop environment

Idea time: RFID+E-Ink, electronic price tags without batteries

Parsing 10TB of Metadata, 26M Domain Names and 1.4M SSL Certs for $10 on AWS