首页 > 其他分享 >hugo 部署到服务器

hugo 部署到服务器

时间:2023-01-18 15:35:39浏览次数:54  
标签:sudo 部署 hugo server nginx html 服务器 root public

创建用户,并有 sudo 权限

useradd xyz
passwd xyz
usermod -aG wheel xyz
sudo -l

检查端口

sudo netstat -tulpn | grep :80
sudo netstat -tulpn | grep :443

安装 nginx

sudo yum install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx

防火墙

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

或者

sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl restart firewalld.service

检查默认网页

在浏览器中输入服务器地址,正常会出现 welcome to nginx。 但是 centos 用户可能会出现 welcome to centos。 这个也是正常的。

上传 hugo public

把 public 文件夹 上传到 xyz 用户目录中

配置 conf

修改 /etc/nginx/nginx.conf, 下面是修改和原版的差别:

[root@kvm-Buffalo nginx]# diff nginx.conf.orig  nginx.conf
5c5,6
< user nginx;
---
> #user nginx;
> user root;
39,40c40,41
<         listen       80;
<         listen       [::]:80;
---
>         listen       80 default_server;
>         listen       [::]:80 default_server;
42c43,44
<         root         /usr/share/nginx/html;
---
>         #root         /usr/share/nginx/html;
>         root         /home/xyz/www/public;
46a49,53
>       location / {
>               root /home/xyz/www/public;
>               index index.html index.htm index.php;
>       }
>
48a56
>               root /home/xyz/www/public;

具体配置如下:

[root@kvm-Buffalo nginx]# cat nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

#user nginx;
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        #root         /usr/share/nginx/html;
        root         /home/xyz/www/public;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                root /home/xyz/www/public;
                index index.html index.htm index.php;
        }

        error_page 404 /404.html;
        location = /404.html {
                root /home/xyz/www/public;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2;
#        listen       [::]:443 ssl http2;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

重启 nginx

sudo nginx -s reload
sudo systemctl status nginx
sudo systemctl restart nginx

再次检查网页

浏览器中重新输入 ip 地址。 如果碰到 403 forbiden. 可以检查 /var/log/nginx 目录下面的两个 log 文件。 正常就是权限不够。

  • 配置中,最开始的 user 改为 root
  • 文件权限不够,把 public 向上的所有父目录,至少有 755 的权限。
  • selinux,就算文件权限够了,selinux 如果开启也会 403。genenforce 检查 selinux,如果开启,vim /etc/selinux/config 改为 SELINUX=disabled, 然后 reboot

同步 public

有多种方式: rsync, ftp, rclone

参考:

hugo博客部署到腾讯云轻量级服务器
https://www.sulvblog.cn/posts/blog/hugo_deploy

Deployment with Rclone
https://gohugo.io/hosting-and-deployment/deployment-with-rclone/

使用Hugo搭建网站并部署到服务器
https://blog.csdn.net/weixin_35436966/article/details/103950907

nginx 访问静态资源文件出现403-forbidden
https://blog.csdn.net/taokeng/article/details/103705342

Centos中的nginx启动成功,但是浏览器却无法访问默认欢迎页面
https://blog.csdn.net/weixin_36332085/article/details/122510422

【解决方案】Nginx安装后,通过IP访问出现CentOS的欢迎界面
https://blog.csdn.net/qq_60923912/article/details/124090550

标签:sudo,部署,hugo,server,nginx,html,服务器,root,public
From: https://www.cnblogs.com/ramlife/p/17059899.html

相关文章

  • 自动化部署活动目录
    WindowsServer2008、WindowsServer2012部署AD1.安装活动目录角色:Install-WindowsFeatureAD-Domain-Services2.导入活动目录的PowerShell命令模块:Import-ModuleADDSD......
  • Centos7 部署NetCore6.0 Web Api
    一、安装dotnet环境第一步sudorpm-Uvhhttps://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm第二步sudoyuminstalldotnet-sdk-6.0......
  • Docker容器化急速部署ClickHouse
    文章目录1.ClickHourse入门简介2.Docker部署ClickHouse3.DBeaver连接ClickHouse1.ClickHourse入门简介(1)什么是行存储传统的OLTP关系型数据库都是行存储一行中......
  • 0x00_kubevsphere_单机部署
    #systemctldisablefirewalld&&systemctlstopfirewalld#sed-is/SELINUX=enforcing/SELINUX=disabled/g/etc/selinux/configsetenforce0#swapoff-as......
  • 100GB以上超大文件上传和断点续传服务器的实现
    ​IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头。 一. 两个必要响应头Accept-Ranges、ETag      ......
  • 前端Linux部署命令与流程记录
    以前写过一篇在Linux上从零开始部署前后端分离的Vue+Springboot项目,但那时候是部署自己的个人项目,磕磕绊绊地把问题解决了,后来在公司有了几次应用到实际生产环境的经验,发......
  • Gitlab集成jenkins及docker自动化部署教程
    Gitlab集成jenkins及docker自动化部署教程能实现提交代码到gitlab后,我们只需要合并代码到指定分支就可以上Jenkins自动拉取最新代码并重新构建部署1、登录Jenkins点击如......
  • 50GB以上超大文件上传和断点续传服务器的实现
    ​ 以ASP.NETCoreWebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API,包括文件的上传和下载。 准备文件上传的API #region 文件上传......
  • Windows环境下实现Jenkins自动化部署
    1.Jenkins部署环境a.下载安装包​​​http://ftp-chi.osuosl.org/pub/jenkins/war-stable/​​​找最新的安装包进行下载(下载时间有点长)b.在安装包根路径下,运行命令jav......
  • Docker下部署Rabbitmq
    1.查询Rabbitmqdockersearchrabbitmq2.拉取Rabbitmqdockerpullrabbitmq:management3.停止、删除、运行dockerstoprabbitmqdockerrmrabbitmqdockerrun-d-p......