标签归档:Nginx

nginx 搭建webdav (基于宝塔)

前提

我们已经有一个可以运行的宝塔面板

具体内容

1. 使用命令 nginx -V,查看当前nginx 是否包含 http_dav_module 模块

2. 新建一个网站,做好域名解析,配置php为纯静态

3. 在网站设置->配置文件的最后添加

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# add 2021-12-26
location / {
root [your path]; #注意修改成自己的目录
#client_max_body_size 102400M; #大文件支持
autoindex on;
dav_methods PUT DELETE MKCOL COPY MOVE;
# 需要 nginx-dav-ext-module 才有下面的选项
dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
create_full_put_path on;
}
# add 2021-12-26 location / { root [your path]; #注意修改成自己的目录 #client_max_body_size 102400M; #大文件支持 autoindex on; dav_methods PUT DELETE MKCOL COPY MOVE; # 需要 nginx-dav-ext-module 才有下面的选项 dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK; create_full_put_path on; }
    # add 2021-12-26
    location / {
        root [your path]; #注意修改成自己的目录
        #client_max_body_size 102400M; #大文件支持
        autoindex on;
        dav_methods PUT DELETE MKCOL COPY MOVE;
        # 需要 nginx-dav-ext-module 才有下面的选项
        dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
        create_full_put_path  on;
    }

4. 在网站目录,中添加账号密码,控制访问权限

至此利用nginx 成功搭建了webdav服务器,可以使用网页或者WinSCP等其他客户端访问

0

树莓派 Web服务器 LNSP

采用LNSP配置(Linux + Nginx + Sqlite + PHP)

1. Nginx

sudo apt-get install nginx,安装

sudo /etc/init.d/nginx start,启动服务

修改 sudo vim /etc/nginx/sites-available/default 其中的部分内容,其他保持不变。

  1. listen 改为8080端口(为了防止和80端口冲突)
  2. index 增加 index.php
  3. 去除php段落的部分注释
  4. html 所在默认路径, root /var/www/html;
server {
    listen 8080 default_server;
    #listen [::]:8080 default_server;    
 
    root /var/www/html; 

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

    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:/run/php/php7.3-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; 
    #} 
}

sudo /etc/init.d/nginx reload,重载。

这时通过系统自带的浏览器访问127.0.0.1:8080,可以看见nginx初始页面。

2. php和sqlite

sudo apt-get install php-fpm php-sqlite3,安装php和sqlite3。

注意使用 php-fpm 和 php-sqlite3 作为默认参数,可以安装最新版本。

在html所在默认路径,新建文件index.php

<?php echo phpinfo(); ?>

期间遇到了一些问题,最初以为是ngnix和php配置的问题,最后发现是因为最初index.php文件里的语法问题,返回HTTP 500的错误。
通过修改sudo vim /etc/php/7.3/fpm/php.ini 文件中 display_errors = On,可以显示出错误所在,进行修正。

3. 反向代理

使用frp作为内网穿透,因为没有多余的域名,只能通过IP访问,所以在frpc.ini 中添加

[Web]
type = tcp
local_ip = 127.0.0.1
local_port = 8080
remote_port = [remote_port]

使用frp的 server_IP:[remote_port]即可以从外网访问处于内网上的树莓派。

4. nginx和php相关指令

/etc/init.d/php-fpm7.3 {start|stop|status|restart|reload|force-reload}
nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}
0

为本站添加了SSL证书

使用浏览器时,您与此网站之间建立的连接不安全 的提醒很碍眼,所以今天为本站添加了SSL证书,启用 https://


申请SSL证书

在阿里云的 云盾证书服务(包年),免费的SLL证书,要先点击Symantec一个域名,就会出现 免费型DV SSL 的选项,然后就可以0元购买。

有两种域名验证方式

  1. DNS验证方式
  2. 文件验证方式

通过验证就申请成功了。然后在证书控制台,下载并安装证书。

下载.pem.key 文件,然后上传到服务器,知道路径就行。


安装SSL证书

这部分,主要是Nginx的操作。虽然使用LNMP一键安装包安装LNMP,但没有使用 lnmp ssl add 添加证书。

我的操作是,修改/usr/local/nginx/conf/vhost 路径下相应站点的 .conf 文件。

server
    {
        listen 80;
        #listen [::]:80;
        server_name blog.francis67.cc francis67.cc;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/blog.francis67.cc;

        #SSL配置从这里新增
        listen 443;
        ssl on;
        ssl_certificate   /usr/local/nginx/conf/vhost/cert/xxx.pem;
        ssl_certificate_key  /usr/local/nginx/conf/vhost/cert/xxx.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        #SSL配置到这里结束

        include rewrite/other.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php-pathinfo.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
         {
            expires      30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/y.log;
        }

重启Nginx服务 /etc/init.d/nginx restart

参考:

  1. [建站基础系列] 07. 常用配置之基于阿里云免费SSL证书开启HTTPS服务
  2. LNMP下Nginx SSL配置的方法详解

typecho设置

  • 配置config.inc.php

文件位于typecho根目录,新增如下内容:

    /** 开启SSL */
    define('__TYPECHO_SECURE__',true);
  • 后台设置

后台管理—>基本设置—>站点地址,将 https://blog.francis67.cc 换成 https://blog.francis67.cc

  • 更换全站链接

使用phpMyadmin在SQL中中执行:

UPDATE typecho_contents SET TEXT = REPLACE( TEXT, 'http://www.opdev.me/', 'https://www.opdev.me/');

  • Chrome警告

找到站点主题目录下的comments.php文件,并搜索$this->commentUrl(),将其替换为:echo str_replace("http","https",$this->commentUrl()); 最后保存。

参考:

  1. Typecho全站启用HTTPS教程
  2. Typecho 全站启用SSL

强制全站https

此时httphttps应该都是可以访问的,如果想只使用https,我们可以我通过Ningx将80端口(HTTPS)重定向到443端口(HTTPS),强制全站HTTPS。

修改/usr/local/nginx/conf/vhost 路径下相应站点的 .conf 文件。

把前面的listen 80;注释掉,再添加一段

server
{
    listen 80;
    server_name blog.francis67.cc francis67.cc;
    rewrite ^(.*) https://blog.francis67.cc$1 permanent;
}

参考:

  1. Nginx强制https,HTTP 301重定向到HTTPS

目前有三张免费SSL证书,分别用在了blog.francis67.ccblog.francis67.ccfile.francis67.cc,都已经启用了https://

0