【安装配置教程】在linux使用nginx部署vue项目

目录

一、安装nginx

二、准备项目dist

三、创建配置文件

四、重新启动nginx,检查端口


一、安装nginx

sudo apt update && sudo apt install nginx -y

二、准备项目dist

        通常情况下,我们的vue项目可以使用npm run build打包成dist文件,其结构如下图

 

        将其通过scp上传至服务器

scp -r my@192.168.8.128:/home/my/

         我习惯将其放在/var/www/目录下,并添加权限,顺便再创建一个文件夹,方便后续的项目管理。

mkdir -p /var/www/newProject
mv /home/my/dist /var/www/newProject/
chmod 777 /var/www/newProject/ && chmod 777 /var/www/newProject/dist

三、创建配置文件

        在/etc/nginx/conf.d/目录下编译配置文件:vue-project.conf

vim /etc/nginx/conf.d/vue-project.conf

        文件内容如下

server {
    listen       90;
    server_name  192.168.8.128; # 替换为域名或服务器IP
    root         /var/www/newProject/dist; # 指向打包后的dist目录
    index        index.html;

    # 处理Vue路由重定向(history模式必须)
    location / {
        try_files $uri $uri/ /index.html;
    }

    # 静态资源缓存(可选优化)
    location ~* \.(js|css|png|jpg|gif|svg|woff2)$ {
        expires 7d;
        add_header Cache-Control "public, immutable";
    }

    # 错误页面(可选)
    error_page 404 /index.html;
}

四、重新启动nginx,检查端口

        接着我们重新启动,检查页面是否成功可以访问

systemctl restart nginx

        访问我们设置的端口

192.168.8.128:90

### 如何在 ggplot2 中设置 `geom_text` 的不同字体系列和样式 在 ggplot2 中,可以利用 `geom_text()` 函数的美学参数(aesthetics),特别是 `family` 和 `fontface` 参数来控制文本的不同字体系列和样式。以下是详细的说明以及示例代码。 #### 使用 `family` 参数指定不同的字体族 `family` 参数允许用户定义所使用的字体家族。默认情况下,ggplot2 支持三种内置字体:`sans`, `serif`, 和 `mono`[^1]。如果需要更多自定义字体,则可以通过扩展包如 `extrafont` 或 `showtext` 来实现更复杂的字体管理。 ```r library(ggplot2) df <- data.frame( x = c(0.4, 0.6, 0.8), y = 1:3, family = c("sans", "serif", "mono"), label = c("Sans Font", "Serif Font", "Mono Font") ) p <- ggplot(df, aes(x, y)) + geom_text(aes(label = label, family = family), size = 10) + xlim(0.2, 1) + ylim(0, 4) print(p) ``` 上述代码展示了如何通过绑定数据框中的变量到 `family` 参数上,从而动态调整每个标签对应的字体族。 --- #### 使用 `fontface` 参数改变字体样式 除了更改字体族外,还可以使用 `fontface` 参数来自定义字体的具体风格,例如常规 (`plain`)、粗体 (`bold`)、斜体 (`italic`) 或加粗并倾斜 (`bold.italic`) 等[^2][^3]。 下面的例子演示了在同一张图中应用多种字体样式的操作: ```r df_fontface <- data.frame( x = rep(c(0.4, 0.6, 0.8), each = 2), y = rep(c(1, 2, 3), times = 2), fontface = c("plain", "bold", "italic", "bold.italic", "plain", "bold"), label = c("Plain Text", "Bold Text", "Italic Text", "Bold Italic Text", "Another Plain", "Yet Another Bold") ) p_fontface <- ggplot(df_fontface, aes(x, y)) + geom_text(aes(label = label, fontface = fontface), size = 10) + xlim(0.2, 1) + ylim(0, 5) print(p_fontface) ``` 此部分代码结合了多个字体样式选项,并将其应用于各自的文本标签之中。 --- #### 组合使用 `family` 和 `fontface` 为了进一步增强可视化效果,可以在同一幅图像里同时配置字体族与字体样式。这有助于区分不同类型的数据或者突出显示某些特定的信息点。 ```r df_combined <- data.frame( x = seq(0.4, 0.9, by = 0.1), y = rep(seq(1, 3, length.out = 6)), family = rep(c("sans", "serif"), each = 3), fontface = rep(c("plain", "bold", "italic"), times = 2), label = paste(rep(c("Sans:", "Serif:"), each = 3), c("Plain", "Bold", "Italic")) ) p_combined <- ggplot(df_combined, aes(x, y)) + geom_text(aes(label = label, family = family, fontface = fontface), size = 10) + xlim(0.2, 1) + ylim(0, 4) print(p_combined) ``` 这段脚本综合运用了前面提到的技术手段,在单一绘图环境中实现了多样化的文字表现形式^. --- ### 总结 以上介绍了如何借助 ggplot2 的核心功能——`geom_text()` 方法完成对图形中文本属性的高度定制化处理过程。无论是简单的字体切换还是复杂多样的视觉修饰需求都可以轻松满足。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

奈何不吃鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值