前端部署过程中遇到的问题记录(nginx)

620 阅读3分钟

1、nginx重启一直不生效

  • 一直是nginx初始化的欢迎页面,没有变化
  • 首先查看/etc/nginx/nginx.conf文件的配置有无错误
  • nginx -t -c /etc/nginx/nginx.conf
nginx -t -c /etc/nginx/nginx.conf
  • 显示以下结果即没有问题

  • 会存在一种情况:配置文件没有出错,但是其中的配置有冲突

  • include /etc/nginx/conf.d/*.confservice配置存在冲突,将include /etc/nginx/conf.d/*.conf注释掉,再重启systemctl restart nginx即可

systemctl restart nginx

2、nginx一直启动失败、80端口占用一直杀不死

  • nginx一直启动失败,报以下错误
Job for nginx.service failed because the control process exited with 
error code. See "systemctl status nginx.service" and "journalctl -xe" 
for details.
  • 使用systemctl start nginx.service命令查看启动状态,根据下图框起来的部分可知是80端口被占用的原因

image.png

  • 使用netstat -nap | grep 80查看80端口存在的进程

  • 常规使用kill -9 pid来结束进程(pid)就是最后那串数字,kill -9 23419
kill -9 pid

kill -9 23419

  • 有时候使用kill -9 pid删除一个80端口进程后又来一个,就可以使用sudo fuser -k -n tcp 80强制杀死
sudo fuser -k -n tcp 80

3、在nginx重启后一直403错误

粗心大意导致在这困了好久,一定要注意,文件是否存在、文件路径是否正确,可以使用pwd得到该文件夹的路径

什么是403错误?

  • 没有权限访问此网站,一般是服务器配置nginx过程中,配置的文件没有相关权限所导致
  • 例:root /root/home;/root/home没有权限或者该目录不存在
server {
    listen       80;
    server_name  _;
    root /root/home; 
    index index.html;

    location / {
     // history模式下需要配置
      try_files $uri $uri/ /index.html;
    }
}

403错误的常见原因及解决方法

  • 1、上文提到的没有权限的原因
    • 检查nginx.conf文件中用户名是否为root,将之改为root拥有最高权限
    • root /root/home;/root/home没有权限或者该目录不存在,使用chomd -R 777 /root/home命令给这个文件夹授权
  • 2、Selinux被设置为了enabled,需要设置为disabled
    • 使用/usr/sbin/sestatus -v命令查看Selinux的值
    • 使用vi /etc/selinux/config命令进行修改Selinux的值,改为disabled
    • 更改之后使用reboot进行重启服务器(!!!⚠️如果这台服务器还部署了公司其他产品记得给leader说一声,不然那个产品用着用着崩了都不知道什么原因)
# This file controls the state of SELinux on the system. 
# SELINUX= can take one of these three values: 
# enforcing - SELinux security policy is enforced. 
# permissive - SELinux prints warnings instead of enforcing. 
# disabled - No SELinux policy is loaded. 
SELINUX=disabled 
# SELINUXTYPE= can take one of three values: 
# targeted - Targeted processes are protected, 
# minimum - Modification of targeted policy. Only selected processes are protected. 
# mls - Multi Level Security protection. 
SELINUXTYPE=targeted

4、本地dist文件怎么上传至服务器

  • 在服务器中先将文件夹删除,再上传dist文件夹
rm -rf dist
  • 在没有借用宝塔的情况下,需要使用命令将项目打包后的dist文件夹上传至服务器
scp  -r local_dir username@servername:remote_dir

例如:
scp -r dist root@192.168.x.x:/root/home/   把当前目录下的dist目录上传到服务器的/root/home目录下

5、VScode插件推荐-Remote-SSH(可视化操作)

  • 安装完后点击➕号即可添加服务器

  • 使用ssh root@xxxxxx连接你的服务器

  • 输入你的服务器密码

  • 连接成功,即可使用打开文件夹打开你需要修改的文件了