centos7远程服务器部署Nginx
- 服务器端的选择和购买配置见 这位小王博主
nginx安装和使用
wget方式安装
1
2
3
4
5
6cd /usr/local
wget -c https://nginx.org/download/nginx-1.13.2.tar.gz
tar -zxvf nginx-1.13.2.tar.gz
cd nginx-1.13.2
./configure
make && make install使用
- 没有进行全局配置的情况下使用
1
2
3
4
5cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s reload
./nginx -s quit - 将nginx添加到全局path中此时可以直接使用nginx来操作代理服务器nginx
1
2
3
4
5vim ~/.bash_profile
//在文件夹最后添加nginx启动的路径
export PATH=$PATH:/usr/local/nginx/sbin
//保存之后执行以下立即生效
source ~/.bash_profile - nginx命令
- 开启
nginx
- 关闭
nginx -s stop
nginx -s quit
- 重启
nginx -s reload
- 查看nginx进程
ps aux|grep nginx
- 查看nginx启动是否成功
nginx -t
- 配置nginx
vim /usr/local/nginx/conf/nginx.conf
每次修改完配置都要重新启动
- 开启
- 其他命令
- 查看当前运行的进程和对应的端口号
netstat -tpnul
- 杀死指定进程端口号
kill -9 端口号用空格分开
- 查看当前运行的进程和对应的端口号
- 在nginx.conf中的端口必须在远程服务器端开放端口外部才能访问(设置见第二部分)
- 开机自启动
链接卸载
- 删除nginx相关文件
1
2
3$ rm -rf /usr/local/nginx
$ rm -rf /var/log/nginx
$ rm -rf /var/temp/nginx - 查找nginx
whereis nginx
find nginx
nginx安装踩坑
图片资源403
1 | # 将nginx.conf文件第一行修改为 |
Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid
1 | nginx -c /usr/local/nginx/conf/nginx.conf |
在nginx的logs文件下生成nginx.pid文件
nginx配置Vue nginx报403问题的解决方法
解决打开nginx.conf配置中nginx创建索引的配置
autoindex on;
1
2
3
4
5
6location /manager {
autoindex on;
alias /home/xxxx/Project/vue/dist;
index index.html;
try_files $uri $uri/ /index.html;
}centos7 ngxin启动失败:Job for nginx.service failed(80端口被占用的解决办法)
查看当前在运行的进程
netstat -tpnul
杀死80端口占用的进程
kill -9 加进程ID
查看httpd正在运行的进程
ps aux |grep httpd
或者直接去修改端口号
注意:nginx详细知识点见链接
nginx在同一个端口下部署多个vue项目
- 参考链接
- 具体使用
- vue项目打包需要设置路径
- 在vue.config.js中设置(项目是在vuecli4.3中),其他版本的需要换一下属性
1
2
3
4module.exports = {
publicPath: `/vueshop`, // 打包后的文件路径
outputDir: `dist/vueshop`, // 打包文件放置在dist文件夹下的vueshop文件夹
} - 在路由router->index.js中修改路由的base,注意这里要和输出的path设置一致,这样在打包之后的访问路径http://xxx:8080/vueshop/
1
2
3
4
5const router = new VueRouter({
mode: 'history',
base: '/vueshop',
routes
})
- 在vue.config.js中设置(项目是在vuecli4.3中),其他版本的需要换一下属性
- vue项目打包需要设置路径
- 在nginx.conf配置文件中设置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34//1.这里需要设置为off,否则会报错路径问题
sendfile off;
server {
listen 80;
server_name localhost;
//2. 根路径设置
root /home/project/dist;
index index.html index.htm;
//3. vue项目1
location /vueshop {
//4.创建索引配置打开
autoindex on;
//5.打包路径的重命名,注意vueshop不要加/,路径会拼接location后面的路径
alias /home/project/dist/vueshop;
//6. $uri/后面不能再接文件夹,访问不到index
try_files $uri $uri/ /index.html;
}
//vue项目2
location /mall {
//创建索引的一定打开,会报403错误
autoindex on;
alias /home/project/dist/mall;
try_files $uri $uri/ /index.html;
}
location / {
root html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
}
centos远程服务器开启端口/防火墙的使用
- 开放端口
1
2
3
4
5
6# 开放80端口
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
# 查看开放的端口号
sudo firewall-cmd --zone=public --list-ports
# 重启防火墙
sudo systemctl restart firewalld.service - 关闭防火墙(外网无法访问时,记得关闭防火墙↓或放开外部访问端口↑)
1
2
3
4
5
6#查看防火墙状态
systemctl status firewalld.service
#关闭防火墙
systemctl stop firewalld.service
#禁止防火墙开机启动
systemctl disable firewalld.servicecentos7上mysql安装和使用
安装和使用
- 安装
yum list installed | grep mysql
#检查系统是否自带msqlyum -y remove 上一步内容
#删除上一步检查出的内容wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
下载mysql的yum源rpm -ivh mysql-community-release-el6-5.noarch.rpm
yum install mysql-community-server
#安装mysql 一路ychkconfig --list | grep mysqld
#检查mysql是否开机启动chkconfig mysqld on
#没有设置开机启动service mysqld start
启动mysql服务
- 设置mysql
1
2
3
4
5
6
71. mysql -u root -p 进入mysql
2.mysql> use mysql;
3.mysql> update user set password=PASSWORD("123456") where User='root';#设置用户密码
4.mysql> flush privileges;#刷新
5.>mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;#远程授权
6.>mysql> flush privileges;
7.>mysql> exit#退出 - 开启防火墙
1
2
3
4
51.firewall-cmd --list-ports#查看防火墙开启的端口,mysql默认3306
2.firewall-cmd --zone=public --add-port=3306/tcp --permanent #如果没有添加3306
3.systemctl stop firewalld.service #停止防火墙
4.systemctl restart firewalld.service #重启防火墙
5.firewall-cmd --list-ports #检查3306是否开启 - 服务器安全组开启
云服务器厂商都提供自设安全组,当需要开放端口时,需要安全组设置
然后就可以远程连接数据库mysql常用命令
- 开启
service mysql start
- 关闭
service mysql stop
- 重启
service mysql restart
- 登录
- 密码明文
语法:mysql -u 用户名 -p用户密码
举例:mysql -u root -p123456
- 密码密文
语法:mysql -u用户名 -p+回车,然后输入密码
- 密码明文
举例:mysql -uroot -p
修改密码
1
2
3
4SET PASSWORD命令(需登录)
语法:mysql> set password for 用户名@localhost = password('新密码');
举例:mysql>set password for root@localhost = password('123456');常用操作
显示数据库列表
show databases;
创建、删除数据库
创建:
create database 数据库名;
drop database 数据库名;
显示库中的数据表
use mysql;
show tables;
显示数据表结构
describe 数据表名;
通过 sql 文件导入数据库
mysql -u用户名 -p密码 < 导入路径
- 或者进入到数据库中通过source导入
1
2
3mysql -u用户名 -p密码
use 数据库名称
source sql文件路径/xx.sql
pm2管理node后台运行
- 在服务器中安装 pm2:npm i pm2 -g
- 启动项目:pm2 start 脚本 –name 自定义名称
- 查看运行项目:pm2 ls
- 重启项目:pm2 restart 自定义名称
- 停止项目:pm2 stop 自定义名称
- 删除项目:pm2 delete 自定义名称
mongodb数据库安装
本文作者:
SparkParis
本文链接: https://sparkparis.github.io/2020/05/26/remoteconfig/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!
本文链接: https://sparkparis.github.io/2020/05/26/remoteconfig/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!