考虑到实现“轻量级”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文件可以正常运作。
下一节,将开始部署内网穿透,通过动态域名解析技术从外部访问网页。
Leave a Reply