树莓派服务器_内网穿透_v*n
安装Nginx
sudo apt-get install nginx
安装失败,解决方法:
修复网络连接,详情请见树莓派网络连接dns配置
更新apt-get
sudo apt-get update
启动 nginx
sudo /etc/init.d/nginx start
显示如下所示即为正常。
[ ok ] Starting nginx (via systemctl): nginx.service.
可以用浏览器登录树莓派ip地址查看是否成功。
修改Nginx
sudo vi /etc/nginx/sites-available/default
对于default进行修改
leafpad /etc/nginx/sites-available/default #修改配置文件:
server {
listen 80; ## 改监听端口号
root xxx; ##默认网页的根目录位置
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
}
创建网页根目录地址:xxx
cd 进入以后输入 sudo vi index.html
<!DOCTYPE html>
<html>
<head>
<title>树莓派.md</title>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<style>
/* https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
body {
font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif);
font-size: var(--vscode-markdown-font-size, 14px);
padding: 0 26px;
line-height: var(--vscode-markdown-line-height, 22px);
word-wrap: break-word;
}
#code-csp-warning {
position: fixed;
top: 0;
right: 0;
color: white;
margin: 16px;
text-align: center;
font-size: 12px;
font-family: sans-serif;
background-color:#444444;
cursor: pointer;
padding: 6px;
box-shadow: 1px 1px 1px rgba(0,0,0,.25);
}
#code-csp-warning:hover {
text-decoration: none;
background-color:#007acc;
box-shadow: 2px 2px 2px rgba(0,0,0,.25);
}
body.scrollBeyondLastLine {
margin-bottom: calc(100vh - 22px);
}
body.showEditorSelection .code-line {
position: relative;
}
body.showEditorSelection .code-active-line:before,
body.showEditorSelection .code-line:hover:before {
content: "";
display: block;
position: absolute;
top: 0;
left: -12px;
height: 100%;
}
body.showEditorSelection li.code-active-line:before,
body.showEditorSelection li.code-line:hover:before {
left: -30px;
}
.vscode-light.showEditorSelection .code-active-line:before {
border-left: 3px solid rgba(0, 0, 0, 0.15);
}
.vscode-light.showEditorSelection .code-line:hover:before {
border-left: 3px solid rgba(0, 0, 0, 0.40);
}
.vscode-light.showEditorSelection .code-line .code-line:hover:before {
border-left: none;
}
.vscode-dark.showEditorSelection .code-active-line:before {
border-left: 3px solid rgba(255, 255, 255, 0.4);
}
.vscode-dark.showEditorSelection .code-line:hover:before {
border-left: 3px solid rgba(255, 255, 255, 0.60);
}
.vscode-dark.showEditorSelection .code-line .code-line:hover:before {
border-left: none;
}
.vscode-high-contrast.showEditorSelection .code-active-line:before {
border-left: 3px solid rgba(255, 160, 0, 0.7);
}
.vscode-high-contrast.showEditorSelection .code-line:hover:before {
border-left: 3px solid rgba(255, 160, 0, 1);
}
.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before {
border-left: none;
}
img {
max-width: 100%;
max-height: 100%;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:focus,
input:focus,
select:focus,
textarea:focus {
outline: 1px solid -webkit-focus-ring-color;
outline-offset: -1px;
}
hr {
border: 0;
height: 2px;
border-bottom: 2px solid;
}
h1 {
padding-bottom: 0.3em;
line-height: 1.2;
border-bottom-width: 1px;
border-bottom-style: solid;
}
h1, h2, h3 {
font-weight: normal;
}
table {
border-collapse: collapse;
}
table > thead > tr > th {
text-align: left;
border-bottom: 1px solid;
}
table > thead > tr > th,
table > thead > tr > td,
table > tbody > tr > th,
table > tbody > tr > td {
padding: 5px 10px;
}
table > tbody > tr + tr > td {
border-top: 1px solid;
}
blockquote {
margin: 0 7px 0 5px;
padding: 0 16px 0 10px;
border-left-width: 5px;
border-left-style: solid;
}
code {
font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
font-size: 1em;
line-height: 1.357em;
}
body.wordWrap pre {
white-space: pre-wrap;
}
pre:not(.hljs),
pre.hljs code > div {
padding: 16px;
border-radius: 3px;
overflow: auto;
}
pre code {
color: var(--vscode-editor-foreground);
tab-size: 4;
}
/** Theming */
.vscode-light pre {
background-color: rgba(220, 220, 220, 0.4);
}
.vscode-dark pre {
background-color: rgba(10, 10, 10, 0.4);
}
.vscode-high-contrast pre {
background-color: rgb(0, 0, 0);
}
.vscode-high-contrast h1 {
border-color: rgb(0, 0, 0);
}
.vscode-light table > thead > tr > th {
border-color: rgba(0, 0, 0, 0.69);
}
.vscode-dark table > thead > tr > th {
border-color: rgba(255, 255, 255, 0.69);
}
.vscode-light h1,
.vscode-light hr,
.vscode-light table > tbody > tr + tr > td {
border-color: rgba(0, 0, 0, 0.18);
}
.vscode-dark h1,
.vscode-dark hr,
.vscode-dark table > tbody > tr + tr > td {
border-color: rgba(255, 255, 255, 0.18);
}
</style>
<style>
/* Tomorrow Theme */
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
/* Tomorrow Comment */
.hljs-comment,
.hljs-quote {
color: #8e908c;
}
/* Tomorrow Red */
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-deletion {
color: #c82829;
}
/* Tomorrow Orange */
.hljs-number,
.hljs-built_in,
.hljs-builtin-name,
.hljs-literal,
.hljs-type,
.hljs-params,
.hljs-meta,
.hljs-link {
color: #f5871f;
}
/* Tomorrow Yellow */
.hljs-attribute {
color: #eab700;
}
/* Tomorrow Green */
.hljs-string,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
color: #718c00;
}
/* Tomorrow Blue */
.hljs-title,
.hljs-section {
color: #4271ae;
}
/* Tomorrow Purple */
.hljs-keyword,
.hljs-selector-tag {
color: #8959a8;
}
.hljs {
display: block;
overflow-x: auto;
color: #4d4d4c;
padding: 0.5em;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
</style>
<style>
/*
* Markdown PDF CSS
*/
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo";
padding: 0 12px;
}
pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
border-radius: 3px;
overflow-x: auto;
white-space: pre-wrap;
overflow-wrap: break-word;
}
pre:not(.hljs) {
padding: 23px;
line-height: 19px;
}
blockquote {
background: rgba(127, 127, 127, 0.1);
border-color: rgba(0, 122, 204, 0.5);
}
.emoji {
height: 1.4em;
}
code {
font-size: 14px;
line-height: 19px;
}
/* for inline code */
:not(pre):not(.hljs) > code {
color: #C9AE75; /* Change the old color so it seems less like an error */
font-size: inherit;
}
/* Page Break : use <div class="page"/> to insert page break
-------------------------------------------------------- */
.page {
page-break-after: always;
}
</style>
<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
</head>
<body>
<script>
mermaid.initialize({
startOnLoad: true,
theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')
? 'dark'
: 'default'
});
</script>
<h1 id="quantum-mini-linux%E7%BD%91%E7%BB%9C%E9%85%8D%E7%BD%AE">Quantum-Mini-Linux—网络配置</h1>
<p><img src="https://files.seeedstudio.com/wiki/Quantum-Mini-Linux-Dev-Kit/Quantum-Mini-Linux-Dev-Kit.png" alt=""></p>
<h2 id="wifi%E8%B4%A6%E5%8F%B7%E5%AF%86%E7%A0%81%E8%AE%BE%E7%BD%AE">wifi账号密码设置</h2>
<p><code>sudo vi /etc/wpa_supplicant/wpa_supplicant.conf</code></p>
<p>修改如下的文件中的部分数据。</p>
<pre class="hljs"><code><div> network={
ssid="[你的网络名称]"
psk="[你的网络密码]"
}
</div></code></pre>
<p>如图<img src="https://exp-picture.cdn.bcebos.com/a44e8afc508c9bcec61993c2d6dd884ce44afa75.jpg?x-bce-process=image/resize,m_lfit,w_500,limit_1/format,f_jpg/quality,q_80" alt=""></p>
<h2 id="%E5%AF%B9%E6%9C%AC%E5%9C%B0%E7%BD%91%E7%BB%9C%E5%9C%B0%E5%9D%80%E8%BF%9B%E8%A1%8C%E9%85%8D%E7%BD%AE">对本地网络地址进行配置</h2>
<p>由于在实验室,所用的路由器的端口号是10.xxx.xxx.xxx 然后直接ip连接到了该位置,这肯定有问题。</p>
<pre class="hljs"><code><div>sudo nano /etc/network/interfaces
</div></code></pre>
<p>修改以下内容设置默认网关,具体数值可以根据自身情况修改</p>
<pre class="hljs"><code><div>auto lo
iface lo inet loopback
auto enxb827bb3ef8a //就是前面查看的名字
iface enxb827bb3ef8a inet static
address 192.168.1.2 //IP地址
netmask 255.255.255.0 //掩码
gateway 192.168.1.1 //网关
</div></code></pre>
<h2 id="%E6%9F%A5%E7%9C%8B%E6%98%AF%E5%90%A6%E8%BF%9E%E6%8E%A5%E6%88%90%E5%8A%9F">查看是否连接成功</h2>
<p>ping 192.168.1.2可以但是无法ping www.baidu.com</p>
<p>报错,unknown host www.baidu.com</p>
<h2 id="%E8%AE%BE%E7%BD%AE%E7%AB%AF%E5%8F%A3">设置端口</h2>
<pre class="hljs"><code><div>sudo vi /etc/resolv.conf
</div></code></pre>
<p>如果你们网络不行的话,那么一定是这个nameserver的问题。</p>
<p>所以,修改</p>
<p>直接在那里面修改。</p>
<p>改成8.8.8.8</p>
<p>:wq保存就可以了。</p>
<p>但是尝试后发现不是因为dns域名解析的问题。</p>
<h2 id="windows%E6%89%BE%E5%88%B0wwwbaiducom%E7%9A%84ip%E5%9C%B0%E5%9D%80">windows找到www.baidu.com的ip地址</h2>
<pre class="hljs"><code><div>win+R
cmd
ping www.baidu.com
</div></code></pre>
<p>百度的地址为14.215.177.39</p>
<p>用linux ping该地址,发现还是无法连接,证明linux没有连接到外网。</p>
<h2 id="linux%E5%A2%9E%E5%8A%A0%E8%B7%AF%E7%94%B1">linux增加路由</h2>
<p>由于linux无法ping通外网,搜索后发现</p>
<p>route</p>
<p>查看路由表,很神奇的是路由表是空的,于是在思考后。</p>
<p>route add default gw 192.168.1.1</p>
<p>route</p>
<p>成功解决树莓派无法上网问题。</p>
<p>shutdown -r now</p>
<h2 id="%E9%80%9A%E8%BF%87putty%E5%8F%AF%E4%BB%A5%E4%BB%8E%E5%B1%80%E5%9F%9F%E7%BD%91ssh%E8%AE%BF%E9%97%AElinux%E5%8F%82%E8%80%83linux%E8%BF%9E%E6%8E%A5%E6%96%B9%E6%B3%95">通过putty可以从局域网ssh访问linux参考linux连接方法</h2>
</body>
</html>
这个是这篇文章的html文件可以直接down我这个网页的html。
展示效果如下所示:
内网穿透
获取域名(内网穿透)
好文请先阅读
https://blog.csdn.net/Mind_programmonkey/article/details/80285596
获取域名
简而言之就是树莓派(及所在网域)没有公网IP,必须先委托代理商做一个映射,在树莓派上道代理商客户端实时告知代理服务器自己的IP,代理服务器(相当于DNS服务器)将域名转换为树莓派IP再告知访问者浏览器
获取方法 ngrok https://www.ngrok.cc/ (免费内网穿透)
注册->申请隧道->http、tcp 都行
验证用户名,密码可填可不填(填上相当于私有)
树莓派上安装客户端 https://www.ngrok.cc/download.html 选 Linux ARM版本
解压,不需要安装
此后我们获得一个隧道 ID
树莓派终端中运行以下命令
cd /home/pi/Dowmloads/linux_arm #进入客户端文件夹
ls # ls查看sunny文件
./sunny clientid 隧道id #执行命令
出现以下界面就表示内网穿透好了,保持运行
如图,表示隧道把 free.idcfengye.com(对应一个公网IP)的19434 端口(如果是http的话就是80端口)映射到127.0.0.1(一个特殊的IP,代表本机)的5228端口。此后,在外网请 free.idcfengye.com:19434 相当于请求本机的 5228 端口 了。
提示:
setsid /home/pi/ngrok/linux_arm/sunny clientid 隧道id &#可以后台启动内网穿透
setsid /home/pi/ngrok/linux_arm/sunny clientid id
自制校园V*N
安装工具:
假如我们想在家里下载学校内网的资源,就需要一个代理服务器在学校内网运行,将tcp请求转发到外网。类似于科学上网的服务器在境外工作,将tcp请求通过合法的网络连接转发到国内。我们用shadowscoks实现这个代理功能。
https://github.com/shadowsocks/shadowsocks/wiki/Shadowsocks-使用说明
sudo pip install --upgrade pip
pip install shadowsocks
配置
https://github.com/shadowsocks/shadowsocks/wiki/Configuration-via-Config-File
在服务端(也就是树莓派啦)
新建文件 /etc/shadowsocks.json
{
"server":"my_server_ip",
"server_port":8388,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"mypassword",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}
注意:
如果是通过隧道连接外网的话:
项目 | Value |
---|---|
my_server_ip | 填127.0.0.1 |
server_port | 填tcp 隧道端口,如5228 |
local_address | 不管 |
local_port | 不管 |
password | 自定义,服务器密码 |
timeout | 默认即可 |
method | 默认即可,客户端需保持一致 |
fast_open | true,可能降低延迟 |
运行
ssserver -c /etc/shadowsocks.json #要在前台运行
ssserver -c /etc/shadowsocks.json -d start#要在后台运行
ssserver -c /etc/shadowsocks.json -d stop
配置为启动脚本
配置为启动脚本,方便开机启动
创建/usr/ss.sh
#!/bin/sh
setsid /home/pi/Dowmloads/linux_arm/sunny clientid 隧道id &#启动内网穿透
ssserver -c /etc/ssserver.json -d restart & #启动ss-server
在exit 0 前添加
/usr/./ss.sh
systemctl start rc-local.service #测试,不能有错误
systemctl status rc-local.service
本文参考
-树莓派实现简单网站服务器