美文网首页
2020-07-22-安装Nginx记录

2020-07-22-安装Nginx记录

作者: 4f528075fae8 | 来源:发表于2020-07-23 03:55 被阅读0次

    更新一下
    sudo apt update
    安装
    sudo apt install nginx
    查看版本
    nginx -v (当前安装的版本是 nginx/1.14.0 Ubuntu 18.04)
    查看状态
    sudo systemctl status nginx 或者 sudo service nginx status

    配置文件
    /etc/nginx/nginx.conf (主配置文件入口)
    之后有 /etc/nginx/conf.d/ (集中式配置)
    sites-enabled -> sites-available 连接配置,有时候不好管理

    启动/停止

    systemctl start nginx
    systemctl stop nginx
    systemctl is-active nginx
    

    重新加载配置文件,而不用下线
    systemctl reload nginx

    查看帮助命令
    nginx -h

    检测配置文件语法
    sudo nginx -t
    大写 -T 的话,会将当前加载的配置输出到 stdout,方便查看全部加载的配置。

    开始配置 sites-enabled
    使用 unlink 命令,去掉连接,因为不需要这样玩。

    放完网站内容之后,配置权限。

    find /var/www/YOURSITE/ -type f -exec chmod 644 {} \;  针对文件
    find /var/www/YOURSITE/ -type d -exec chmod 755 {} \; 针对目录
    

    请求十次
    for i in {1..10}; do curl localhost > /dev/null; done
    如果是目录,则要在末尾加 /
    for i in {1..10}; do curl localhost/images/ > /dev/null; done

    故障检查:检查端口有没有正常
    sudo lsof -P -n -i :80 -i :443 | grep LISTEN
    lsof 表示 list open file
    另一种
    sudo netstat -plan | grep nginx
    最后查看日志
    tail -f /var/logs/nginx/*.log

    systemctl status nginx mysqld php7.2-fpm | grep -E "(Loaded|Active)" 查看情况

    灌入数据
    msyql -u admin -padmin appointments < appointment_database.sql

    nginx 级别限制访问

    location /appointemtns/ {
      allow 192.168.0.0/24;
      allow 10.0.0.0/8;
      deny all;
    }
    

    基础的 http basic 验证
    不用安装 apache2 而只是使用它们的工具 apache2-utils
    安装使用的命令: sudo apt install apache2-utils -y
    之后用来创建密码:
    sudo htpasswd -c /etc/nginx/passwords admin
    注意首次运行才使用 -c
    后面再次添加新用户就不用 -c,否则会覆盖掉原来的文件。
    sudo htpasswd /etc/nginx/passwords user1
    再次运行,同样的用户名,则是更新密码的。
    删除用户则是:
    sudo htpasswd -D /etc/nginx/passwords user2

    由于密码文件只是文本,所以,修改权限,只允许 nginx的用户(即 www-data) 和 root 访问

    1. 修改用户
      sudo chown www-data /etc/nginx/passwords
    2. 修改权限
      sudo chmod 600 /etc/nginx/passwords

    接着配置 Nginx 使用这个密码文件。

    location / {
            auth_basic "Authentication is required...";
            auth_basic_user_file /etc/nginx/passwords;
            try_files $uri $uri/ =404;
    }
    

    接下来开始玩 SSL/TLS
    先试试自签名的

    sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/nginx.key -out /etc/ssl/certs/nginx.crt
    

    现在是使用 腾讯 的证书
    sudo cp YOURKEY.key /etc/ssl/private/
    sudo cp YOURCERT.crt /etc/ssl/certs/

    openWrt 更新

    opkg update
    opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade
    

    相关文章

      网友评论

          本文标题:2020-07-22-安装Nginx记录

          本文链接:https://www.haomeiwen.com/subject/eddxlktx.html