前言
本篇文章主要是为了保存记录下(日记)配置的过程,其中有什么不对的望大佬指出,如果对一些朋友有帮助就更好了。
一、服务器选择
- 因为自己网站只是做个简单的前端页面展示,而且平时用户基本上不多,所以这里选择服务器的配置为1核2G 1带宽(服务器选择阿里云,华为云,腾讯云的都可)(而且现在基本有免费使用1个月的活动)想玩的小伙伴都可以试着配置下
- 预装镜像选择 centOs 7.6,其它的不变
二、服务器管理 - FinalShell安装
- FinalShell是一体化的的服务器,网络管理软件,不仅是ssh客户端,还是功能强大的开发,运维工具,充分满足开发,运维需求.
- 特色功能:
云端同步,免费海外服务器远程桌面加速,ssh加速,本地化命令输入框,支持自动补全,命令历史,自定义命令参数 - 不同系统有不同的安装方式 下面可以看看
Windows版下载地址:<http://www.hostbuf.com/downloads/finalshell_install.exe>
macOS版下载地址: [http://www.hostbuf.com/downloads/finalshell_install.pkg]
mac版安装路径 /Applications/FinalShell.app/
配置文件路径 /Users/$USER/Library/FinalShell/
mac版卸载
删除安装目录 /Applications/FinalShell.app/
Linux版安装及教程:
<http://www.hostbuf.com/t/1059.html>
下载完打开-接着我们一步一步配置跟我们的服务器进行连接
点击 - 连接 - 打开
- 这样我们就实现了与服务连接接着我们就可以在上面操作我们的服务器进行相应的配置
- 但你会发现上传跟下载文件比较麻烦 那就解决下吧
- 在打开的finalshell 输入
yum -y install lrase会得rz 跟 sz相关的命令
二、nginx安装
- 输入以下指令,然后按回车。(使用vim编辑器编辑nginx.repo)
vim /etc/yum.repos.d/nginx.repo
- 按i进入编辑模式,底部出现“插入”则说明成功进入编辑模式
3. 添加nginx 仓库源 类似于npm
通过添加 Nginx 软件包的仓库源,您可以使用系统自带的包管理器(如 `yum`)在 CentOS 系统上安装和更新 Nginx,而不需要手动下载和安装软件包。这样可以简化安装和更新过程,并确保您使用的是最新的版本和修复了已知漏洞的软件包。
要操作,您可以按照以下步骤:
1. 打开终端并使用 root 用户登录 CentOS 系统。
1. 编辑 `/etc/yum.repos.d/nginx.repo` 文件,将其中 `[nginx-stable]` 或
`[nginx-mainline]` 的 `enabled` 属性设置为 `1`(启用)或 `0`(禁用),以启用或禁用相应的仓库源。
1. 运行 `yum update` 命令以更新系统的软件包缓存。
1. 运行 `yum install nginx` 命令以安装 Nginx。如果您需要其他版本或模块,请使用相应的软件包名称进行安装。
请注意,如果您在 CentOS 系统上使用了其他 Web 服务器(如 Apache),则需要先停止该服务器,然后再启动 Nginx。
复制以下代码,粘贴进去(注意别用ctrl+v粘贴,在finalshell里点击鼠标右键,然后选择粘贴)
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
注意每行开头不能有空格,否则可能会报错(vim编辑器不适用左键改变光标位置,可以通过上下左右控制)
4. 复制完确认没问题后,点击键盘上的esc退出编辑模式,然后输入:wq保存并退出 Vim 编辑器(注意输入法一定要是英文模式)
5. 输入指令安装nginx
yum install -y nginx
6.检查nginx 安装状态
systemctl status nginx
7. 上面这个说明nginx已经安装成功,但是未启动,现在启动一下nginx,启动后再次查看nginx状态,出现active (running)说明启动成功
systemctl start nginx
8. 查看80端口是否被nginx占用,然后在浏览器地址栏直接访问你的公网ip地址,如果出现nginx提示,则说明nginx已经配置OK。
ps -ef | grep nginx
9. 输入ip能访问到这个页面说明ok了
三、nginx配置
- 在你的电脑新建个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;
# 这一行指定了nginx进程的运行用户,这里是nginx。
worker_processes auto;
# 这一行指定了nginx使用的进程数,auto表示根据CPU核数自动设置。
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# 这两行分别指定了错误日志和进程ID文件的路径。
# 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推送
tcp_nodelay on;
# TCP延迟
keepalive_timeout 65;
# 保持连接超时时间设置
types_hash_max_size 2048;
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;
# 每个web服务一个server
server {
listen 80 default_server;
# 监听端口
listen [::]:80 default_server;
server_name 你的域名 www.你的域名;
# 监听域名
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
# 对应的文件目录
location / {
root /usr/local/dist;
# 文件目录
index index.html;
# 入口文件
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
# ssl https - 文件配置
# server {
# listen 443 ssl;
# # listen [::]:443 ssl http2 default_server;
# server_name 你的域名 www.你的域名;
# root /usr/share/nginx/html;
# # 下载证书 会得到两个文件 .crt .key 分别配置
# ssl_certificate "cert/server.crt";
# ssl_certificate_key "cert/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
# ssl_prefer_server_ciphers on;
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
# location / {
# # 文件对于的配置跟上面一样
# root /usr/local/dist;
# index index.html;
# }
# error_page 404 /404.html;
# location = /40x.html {
# }
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
2.进去nginx 目录
cd /etc/nginx
3.复制保存原来的nginx.conf
cp nginx.conf nginxCopy.conf
4.删除原来的nginx.conf
rm -rf nginx.conf
- 上传我们的nginx.conf到对应的目录
rz
选择对应的目录 - 然后用 ls 查看当前目录的文件情况 - 这里记得把自己的域名改上去 没有的话就去掉 6. 测试下配置文件是否有错
nginx -t
显示这个就是对的
7. 将前端文件上传到服务器
cd /usr/loacl
将dist 拉进去 或者用rz 丢上去
8. 重载nginx 配置
/usr/sbin/nginx -s reload
然后再次访问服务器的公网ip,就可以访问到前端页面啦! 这里参考了
服务配置:
https://juejin.cn/post/7242502779469692984?searchId=20230722100227F35CC7F64B787A322646#comment
nginx详细配置:
https://juejin.cn/post/7211702508371656759?searchId=20230722095736C9394F8A6759EF317AB5
感谢阅读