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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Nginx >内容正文

Nginx

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

發(fā)布時(shí)間:2023/12/14 Nginx 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx源码安装,配置开机自启 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

背景

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

系統(tǒng)環(huán)境

在 CentOS7 上進(jìn)行安裝,虛擬主機(jī)信息如下:

[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# 配置環(huán)境變量 [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:

啟動(dòng)驗(yàn)證

# 啟動(dòng) [root@hadoop1 nginx-1.20.1]# nginx -c /usr/local/nginx/conf/nginx.conf

通過(guò)80端口訪問(wèn),看 Nginx 是否啟動(dòng)成功。

配置開機(jī)自啟

# 這里是用源碼編譯安裝的,所以需要手動(dòng)創(chuàng)建nginx.service服務(wù)文件。 [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

驗(yàn)證開機(jī)自啟

[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  啟動(dòng)nginx服務(wù) systemctl stop nginx.service  停止服務(wù) systemctl restart nginx.service  重新啟動(dòng)服務(wù) systemctl status nginx.service 查看服務(wù)狀態(tài) systemctl enable nginx.service 設(shè)置開機(jī)自啟動(dòng) systemctl disable nginx.service 取消開機(jī)自啟動(dòng)# 查看開機(jī)啟動(dòng)項(xiàng) systemctl list-unit-files systemctl list-unit-files | grep enabled systemctl list-unit-files | grep nginx

Note:

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

    關(guān)于 Nginx ,我之前總結(jié)過(guò)各種掉進(jìn)的坑以及如何跳出的解決方法。如果恰巧你也遇到了類似問(wèn)題,那么很高興能夠?yàn)槟愎?jié)省點(diǎn)時(shí)間。

    歷史文章鏈接:

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

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

    Your comments and suggestions are welcome!

    總結(jié)

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

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。