小工具知识网

当前位置: 首页 > 行业知识 > linux安装ngnix完整步骤(支持centos/银河麒麟操作系统)

行业知识

linux安装ngnix完整步骤(支持centos/银河麒麟操作系统)

2026-11-07 20:28:09 来源:互联网转载

linux安装ngnix(支持centos/银河麒麟操作系统)

  • 本次操作系统安装ngnix采用离线或在线安装方式,离线就是不联网环境,在线则是联网环境;
  • 支持centos7或centos8或国产操作系统(银河麒麟高级服务器操作系统)
  • 如果是银河麒麟高级服务器操作系统,查看该服务的信息命令如下:
  • ���看服务器信息:nkvers(服务器)
  • 开发语言版本:java -version

    1. 下载nginx

    • 安装目录/usr/local
    • 选择需要的版本进行安装
      cd /usr/local

      #未联网的情况下:http://nginx.org/en/download.html

      • 下载需要的安装包,然后上传到安装目录下/usr/local

      • #联网的情况下,通过命令下载:

        curl -O http://nginx.org/download/nginx-1.22.1.tar.gz

        2. 解压

        tar -zxvf nginx-1.22.1.tar.gz

        3. 进入nginx-1.22.1目录

        cd nginx-1.22.1

        4. 执行配置

        ./configure

        5. 执行 make

        • 执行成功

          6. 执行 make install

          • 执行完后,在/usr/local目录下生成了一个nginx

            7. 启动nginx

            cd /usr/local/nginx/sbin ./nginx
            • nginx配置默认端口是80

              8. 浏览器直接访问:http://192.168.124.56

              • nginx欢迎界面则表示nginx部署成功
              • 如果要修改nginx端口,则进入nginx.conf目录
              • vim nginx.conf
              • 修改保存后

                9. 重启Nginx

                # 停止nginx/usr/local/nginx/sbin/nginx -s quit# 启动nginx/usr/local/nginx/sbin/nginx 
                • 访问http://192.168.124.56:9000

                • 此时访问80端口已经访问不到了

                • nginx相关命令

                  #强制停止nginx/usr/local/nginx/sbin/nginx -s stop#重新加载配置文件/usr/local/nginx/sbin/nginx -s reload # 重启 Nginx/usr/local/nginx/sbin/nginx -s reopen# 启动 Nginx/usr/local/nginx/sbin/nginx 

                  10. 设置开机自启

                  vim /lib/systemd/system/nginx.service
                  • 在nginx.service中添加以下内容
                    Description=nginx - high performance web serverAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s stop[Install]WantedBy=multi-user.target
                    • 重新加载配置
                      # 重新加载配置systemctl daemon-reload# 设置开启自动启动systemctl enable nginx.service# 停止/usr/local/nginx/sbin/nginx -s quit# 强制停止/usr/local/nginx/sbin/nginx -s stop
                      • 注意:必须先执行/usr/local/nginx/sbin/nginx -s stop停止nginx后,才能使用systemctl XXX nginx的先关命令
                      • 查看状态 systemctl status nginx
                      • systemctl 启动nginx相关命令
                        # 重新加载配置systemctl daemon-reload# 设置开启自动启动systemctl enable nginx.service# 修改nginx配置后重新加载配置systemctl reload nginx# 重启nginxsystemctl restart nginx.service# 或者systemctl restart nginx# 停止nginxsystemctl stop nginx.service# 或者systemctl stop nginx# 启动nginxsystemctl start nginx.service# 或者systemctl start nginx# 查看nginx状态systemctl status nginx.service# 或者systemctl status nginx
                        • 停止容器systemctl stop nginx
                        • 重启容器 systemctl restart nginx
                        • 注意,每次修改nginx.conf后必须重新加载配置文件,才能生效
                          # 修改nginx配置后重新加载配置systemctl reload nginx# 重启nginxsystemctl restart nginx# 查看nginx状态systemctl status nginx

上一篇:程咬金下载攻略,一键获取游戏应用,轻松上手!

下一篇:bananaplease怎么读?