2. 在Linux 当中安装 Nginx(13步) 下载&安装&启动(详细说明+附加详细截图说明)
2. 在Linux 當中安裝 Nginx(13步) 下載&安裝&啟動(詳細說明+附加詳細截圖說明)
@
- 2. 在Linux 當中安裝 Nginx(13步) 下載&安裝&啟動(詳細說明+附加詳細截圖說明)
- 1. 在 Linxu 下安裝 Nginx 的詳細步驟
- 2. 最后:
1. 在 Linxu 下安裝 Nginx 的詳細步驟
Nginx 官方下載地址:https://nginx.org/en/download.html
注意:保證Linux 虛擬機可以訪問到外網:
[root@localhost bin]# ping www.baidu.com
具體的安裝步驟如下:
- 搭建 gcc 環境
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
特別的:
- 一定要保證當前的 linux 系統, 可以連接外網, 因為 yum 需要到外網,獲取數據
- 如 何 在 Linux 配 置 網 絡 , 可 以 連 接 到 外 網 , 大家可以移步至:韓老師的教學https://www.bilibili.com/video/BV1Sv411r7vd?p=63
- 執行上面指令的時候, 可能會報
Centos Another app is currently holding the yum lock..錯誤, 是因為 yum 不時會自動升級, 占用了端口或文件, 解決方案 :
- 可以重啟 Linux, 立即執行該指令
- 或 者等一會再執行
- 或者參考 https://www.cnblogs.com/lzxianren/p/4254059.html
可以執行如下指令:查看 gcc 安裝的版本信息:
[root@localhost bin]# gcc --version
或者
[root@localhost bin]# gcc -v
安裝 gcc 提示一些鏡像失敗的問題:yum 安裝軟件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解決方法(2024更新),大家可以移步至: [Linux 用yum安裝軟件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解決方法(2024更新)-CSDN博客](Linux 用yum安裝軟件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解決方法(2024更新)-CSDN博客) 嘗試解決,親測有效。
- 通過 Xftp 將
nginx-1.20.2.tar.gz上傳到Linux /opt目錄當中
一般,在 Linux 當中都是將安裝軟件放到 opt 目錄下
進入到 opt 目錄當中查看,是否上傳成功。
[root@localhost opt]# cd /opt
- 切換到
/opt目錄 將上傳的nginx-1.20.2.tar.gz文件解壓
[root@localhost opt]# tar -zxvf nginx-1.20.2.tar.gz
4. 將解壓后的文件放到指定位置/usr/local/nginx 文件目錄當中
[root@localhost opt]# mv nginx-1.20.2 /usr/local/nginx
5. 進入到 /usr/local/nginx文件目錄當中
[root@localhost opt]# cd /usr/local/nginx
6. 配置 nginx 路徑
注意:一定要進入到 nginx 目錄當中去,才行。因為只有在 nginx 目錄下,才有這個我們編排的 :configure 文件夾。才能執行如下指令。
./configure
--prefix=/usr/local/nginx
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--with-http_gzip_static_module
--http-client-body-temp-path=/var/temp/nginx/client
--http-proxy-te
mp-path=/var/temp/nginx/proxy
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi
--http-scgi-temp-path=/var/temp/nginx/scgi
--conf-path=/usr/local/nginx/nginx.conf
7. 補全 nginx 配置目錄
執行如下命令
mkdir /var/temp/nginx -p
8. 編譯并安裝
執行如下命令:
make && make install
執行:
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
重新configure,執行下邊命令:
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module重新編譯,執行下邊命令:
make && make install
如果還是安裝失敗的:可以看看這篇文章https://blog.csdn.net/y2020520/article/details/131187585
9. 測試配置與 nginx 是否正常,當出現 successful 即可
[root@localhost nginx]# ./sbin/nginx -t
10. 啟動 nginx
./sbin/nginx -c # 啟動Nginx
./sbin/nginx -c nginx.conf # 啟動 Nginx ,同時指明是通過哪個路徑下的 nginx.conf 配置文件進行啟動,不寫明,則是啟動 /usr/local/nginx/conif 默認路徑下面的 nginx.conf 進行啟動 nginx 的
# 注意:這里我們是在 Nginx 目錄下其啟動的,所以用的是:./sbin
絕對路徑進行啟動的方式:
/usr/local/nginx/sbin/nginx -c
啟動 Nginx 可能的錯誤 和解決方案
解決 nginx 啟動報錯 nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
pid /usr/local/nginx/logs/nginx.pid;
[root@localhost conf]# mkdir /usr/local/nginx/log
11. 查看進程/或端口(默認端口是 80)
[root@localhost nginx]# ps -ef | grep nginx
root 2477 1 0 20:07 ? 00:00:00 nginx: master process ./sbin/nginx
nobody 2488 2477 0 20:08 ? 00:00:00 nginx: worker process
root 2519 2417 0 20:10 pts/0 00:00:00 grep --color=auto nginx
注意:養成一個好習慣,每次啟動任何服務器,都執行一下
ps -ef | grep xxx查看該服務器是否啟動成功了。
12. 驗證Nginx 是否安裝成功
nginx 默認監聽端口 80,出現 Welcome to nginx!該頁面就是搞定了
Linux 的瀏覽器:http://localhost
13. 配置防火墻,讓 Windows 訪問 Nginx
說明:默認情況下 Windows 是不能訪問 Nginx , 因為Linux虛擬機是當中防火墻是關閉 80 端口的,關閉了,外界是無法訪問到 80端口的。所以我們需要將其打開,讓外界我們的 windows 可以訪問到 80 端口。
查看開放的端口號
[root@localhost nginx]# firewall-cmd --list-all
設置開放的端口號
#firewall-cmd --add-service=http --permanent #增加了一個 http 服務,理解
firewall-cmd --add-port=80/tcp --permanent
重啟防火墻,只有重啟了防火墻,你對防火墻的配置才會生效 。
firewall-cmd --reload
重啟后,再次執行,查看防火墻開放的端口信息:
[root@localhost nginx]# firewall-cmd --list-all
測試: windows 瀏覽器上輸入:[Linux ifconfig 查看到的IP地址]+80端口 : http://192.168.12.134/
補充:
查看 Nginx 的版本信息指令:
[root@localhost nginx]# ./sbin/nginx -v
重啟 Nginx的指令:該指令也是在 Nginx 安裝目錄下執行的。
[root@localhost nginx]# ./sbin/nginx -s reload
2. 最后:
“在這個最后的篇章中,我要表達我對每一位讀者的感激之情。你們的關注和回復是我創作的動力源泉,我從你們身上吸取了無盡的靈感與勇氣。我會將你們的鼓勵留在心底,繼續在其他的領域奮斗。感謝你們,我們總會在某個時刻再次相遇。”
總結
以上是生活随笔為你收集整理的2. 在Linux 当中安装 Nginx(13步) 下载&安装&启动(详细说明+附加详细截图说明)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Golang 实现本地持久化缓存
- 下一篇: Linux MiniMal版本常规所需环