一、安裝gcc gcc-c++
yum install -y gcc gcc-c++
二、下載下傳tar.gz包
下載下傳位址http://nginx.org/en/download.html
三、安裝
#根目錄使用ls指令可以看到下載下傳的nginx壓縮包,然後解壓
tar -zxvf nginx-1.16.1.tar.gz
#解壓後進入目錄
cd nginx-1.16.1
#使用預設配置
./configure
#編譯安裝
make
make install
#查找安裝路徑,預設都是這個路徑
[[email protected]_0_12_centos ~]# whereis nginx
nginx: /usr/local/nginx
#啟動、停止nginx
cd /usr/local/nginx/sbin/
./nginx #啟動
./nginx -s stop #停止,直接查找nginx程序id再使用kill指令強制殺掉程序
./nginx -s quit #退出停止,等待nginx程序處理完任務再進行停止
./nginx -s reload #重新加載配置檔案,修改nginx.conf後使用該指令,新配置即可生效
#重新開機nginx,建議先停止,再啟動
./nginx -s stop
./nginx
#檢視nginx程序,如下傳回,即為成功
[[email protected]_0_12_centos ~]# ps aux|grep nginx
root 5984 0.0 0.0 112708 976 pts/1 R+ 14:41 0:00 grep --color=auto nginx
root 18198 0.0 0.0 20552 612 ? Ss 11:28 0:00 nginx: master process ./nginx
nobody 18199 0.0 0.0 23088 1632 ? S 11:28 0:00 nginx: worker process
四、開機自啟動
#在rc.local增加啟動代碼即可
vi /etc/rc.local
#增加一行 /usr/local/nginx/sbin/nginx,增加後儲存
#設定執行權限
cd /etc
chmod 755 rc.local
浏覽器輸入伺服器ip即可看到nginx歡迎界面
五、配置域名映射
#進入nginx配置檔案目錄,找到nginx的配置檔案nginx.conf
cd /usr/local/nginx/conf/
#直接修改
vi nginx.conf
在檔案中找到如圖位置
#listen為監聽的端口
listen 80;
#server_name為域名
server_name www.test.com;
#location是通路位址的設定,locahost也可以用伺服器ip代替
location / {
proxy_pass http://localhost:8080;
}
如圖,隻需要修改server_name和location裡面的内容即可
#修改完成後,重新加載配置檔案
cd /usr/local/nginx/sbin/
./nginx -s reload
六、進入域名控制台,添加或者修改解析位址
如果原來配置了解析,新解析需要一定時間才能生效
注:收集于網絡,侵權請聯系作者