Do Note

儒道佛魔修心地

树莓派搭建轻量级Web服务器[2]


考虑到实现“轻量级”Web服务器的要求,本案例摈弃了传统了LAMP(linux + apache + mysql + php)以及LNMP(linux + nginx + mysql + php)构架,而采用了更为轻便的LNSP构架,即linux + nginx + sqlite + php

部署nginx服务器

1.运行sudo apt-get install nginx,安装nginx软件包。
2.运行sudo /etc/init.d/nginx start,启动nginx服务。
3.运行sudo vi /etc/nginx/sites-available/default,修改server中的代码如下:

server {
listen 80 default_server;
#listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

部署php和sqlite服务

1.运行sudo apt-get install php7.0-fpm php7.0-sqlite3,安装php和sqlite软件包。
2.运行sudo /etc/init.d/nginx reload,重新加载nginx的配置。

测试LNSP构架响应

1.浏览器内直接访问树莓派IP地址,见到如下画面,表示可以正常访问静态html页面。

2.运行sudo vi /var/www/html/index.php,新建测试用php文档。输入下列code:

<?php
print <<< EOT
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test successful</title>
</head>
<body>
<h1>Test successful</h1>
<p>Congratulations.</p>
<p>Your webserver and PHP are working.</p>
</body>
</html>
EOT;
?>

 

3.浏览器内打开树莓派IP/index.php,见到下面状态则表示php文件可以正常运作。

下一节,将开始部署内网穿透,通过动态域名解析技术从外部访问网页


2 responses to “树莓派搭建轻量级Web服务器[2]”

  1. […] 至此,基本的轻量级Web服务器框架已经全部部署完成,下一篇将搭建具体的网站程序于LNSP构架。 […]

  2. […] 在之前所部署的基于树莓派的LNSP系统上,可直接搭建网站程序进入到终端访问环节。随着近些年琳琅满目PHP应用的诞生,网站/博客程序早已铺天盖地,这其中有着以公司为背景支撑的wordpress,也有小团队自主开发的Typecho,此外也有许多近些年发展起来的静态博客生成系统。这里,不再赘述和比较各家产品的优劣,直接以Wordpress为例,部署在轻量级Web服务器上。 […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.