CentOS 7安装Nginx
生活随笔
收集整理的這篇文章主要介紹了
CentOS 7安装Nginx
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.虛擬機網絡模式改為橋接,ip地址改為靜態
可以在網上查閱
2. 關閉防火墻
停止防火墻服務
關閉開機自啟
systemctl disable firewalld.service3.?安裝nginx依賴
這里一定要安裝好,不然下面會報錯,錯誤為:nginx c compiler cc is not found.
yum -y install gcc-c++ pcre-devel zlib-devel openssl-devel4.?安裝wget
yum -y install wget5.?安裝nginx
下載源碼包
解壓
tar -zxvf nginx-1.17.2.tar.gz進入解壓出來的文件夾
cd nginx-1.17.2預編譯
./configure --with-http_ssl_module --prefix=/usr/local/nginx安裝
make && make install6.?修改環境變量
編輯環境變量配置文件
在空白處輸入:
PATH=$PATH:/usr/local/nginx/sbin export PATH保存文件后刷新
source /etc/profile7.?修改端口
編輯nginx配置文件
將listen 80改成如圖所示的listen 8080
8.?使用systemctl控制nginx
創建systemctl服務文件
將以下內容輸入:
[Unit] Description=nginx - high performance web server After=network.target remote-fs.target nss-lookup.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 stop[Install] WantedBy=multi-user.target保存,使文件生效:
systemctl daemon-reload然后就可以使用如下命令進行控制:
啟動nginx服務: systemctl start nginx.service 設置開機自啟動: systemctl enable nginx.service 停止開機自啟動: systemctl disable nginx.service 查看服務當前狀態: systemctl status nginx.service 重新啟動服務: systemctl restart nginx.service9.啟動nginx,并設為開機自啟
systemctl start nginx.service systemctl enable nginx.service10. 訪問nginx
在瀏覽器中輸入“當前CentOS的ip:8080”,如192.168.1.1:8080
如果出現下面圖片,就說明安裝成功了。
總結
以上是生活随笔為你收集整理的CentOS 7安装Nginx的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL--安装及配置
- 下一篇: CentOS 7安装Keepalived