日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx源码安装,配置开机自启

發布時間:2023/12/14 Nginx 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx源码安装,配置开机自启 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

背景

最近,全球都在制裁 Nginx , ClickHouse 的誕生地。以前都是通過 yum 直接安裝的 Nginx ,今天試試源碼安裝。

系統環境

在 CentOS7 上進行安裝,虛擬主機信息如下:

[root@hadoop1 local]# uname -a Linux hadoop1 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux [root@hadoop1 local]# cat /proc/version Linux version 3.10.0-1127.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) #1 SMP Tue Mar 31 23:36:51 UTC 2020 [root@hadoop1 local]# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core)

下載解壓

# 下載 [root@hadoop1 local]# wget http://nginx.org/download/nginx-1.20.1.tar.gz# 解壓 [root@hadoop1 local]# tar -xvf nginx-1.20.1.tar.gz

編譯安裝

[root@hadoop1 local]# cd nginx-1.20.1 [root@hadoop1 nginx-1.20.1]# ./configure [root@hadoop1 nginx-1.20.1]# make [root@hadoop1 nginx-1.20.1]# make install# 配置環境變量 [root@hadoop1 nginx-1.20.1]# nginx -V -bash: nginx: 未找到命令 [root@hadoop1 nginx-1.20.1]# vi /etc/profile export NGINX_HOME=/usr/local/nginx export PATH=$PATH:$NGINX_HOME/sbin# 刷新配置 [root@hadoop1 nginx-1.20.1]# source /etc/profile[root@hadoop1 nginx-1.20.1]# nginx -V nginx version: nginx/1.20.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) configure arguments:

啟動驗證

# 啟動 [root@hadoop1 nginx-1.20.1]# nginx -c /usr/local/nginx/conf/nginx.conf

通過80端口訪問,看 Nginx 是否啟動成功。

配置開機自啟

# 這里是用源碼編譯安裝的,所以需要手動創建nginx.service服務文件。 [root@hadoop1 nginx-1.20.1]# vi /lib/systemd/system/nginx.service [Unit] Description=nginx service After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target

驗證開機自啟

[root@hadoop1 nginx-1.20.1]# systemctl list-unit-files | grep nginx nginx.service disabled [root@hadoop1 nginx-1.20.1]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. [root@hadoop1 nginx-1.20.1]# systemctl list-unit-files | grep nginx nginx.service enabled

常用命令

# Nginx啟停 systemctl start nginx.service  啟動nginx服務 systemctl stop nginx.service  停止服務 systemctl restart nginx.service  重新啟動服務 systemctl status nginx.service 查看服務狀態 systemctl enable nginx.service 設置開機自啟動 systemctl disable nginx.service 取消開機自啟動# 查看開機啟動項 systemctl list-unit-files systemctl list-unit-files | grep enabled systemctl list-unit-files | grep nginx

Note:

  • 修改完配置后,可通過nginx -t測試配置是否存在語法錯誤或者typo;
  • 修改完配置后,記得通過nginx -s reload刷新使配置生效;
  • Reference

    關于 Nginx ,我之前總結過各種掉進的坑以及如何跳出的解決方法。如果恰巧你也遇到了類似問題,那么很高興能夠為你節省點時間。

    歷史文章鏈接:

    • 入門Nginx之-靜態資源服務器及跨域配置
    • 入門Nginx之-反向代理實現二級域名轉發
    • 入門Nginx之-負載均衡(SpringBoot)
    • 入門Nginx之-代理Websocket
    • 入門Nginx之-代理HTTPS, HTTP強制轉HTTPS
    • Nginx配置開啟HTTP2支持
    • openssl版本升級后,Nginx用的還是舊版的openssl
    • 在華為鯤鵬openEuler20.03系統上安裝Redis, Zookeeper, Nginx
    • 全棧開發之前、后端服務部署:Nginx源碼安裝,反向代理,靜態資源服務,生產環境跨域,負載均衡

    If you have any questions or any bugs are found, please feel free to contact me.

    Your comments and suggestions are welcome!

    總結

    以上是生活随笔為你收集整理的Nginx源码安装,配置开机自启的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。