文章目錄
Yum在線安裝
http://nginx.org/en/linux_packages.html#RHEL-CentOS
在新機器上首次安裝nginx之前,您需要設置nginx軟件包存儲庫。之後,您可以從存儲庫中安裝和更新nginx。
1.安裝先決條件:
sudo yum install yum-utils
2. 設置yum存儲庫
請創建名爲 /etc/yum . repo . d/nginx . repo 的文件,其中包含以下內容:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
3. 選擇儲存庫
默認情況下,使用穩定nginx包的存儲庫。如果您想使用主線nginx包,請運行以下命令:
sudo yum-config-manager --enable nginx-mainline
4.安裝nginx
運行以下命令:
sudo yum install nginx
5.啓動:
systemctl start nginx
tar安裝
1.安裝依賴包
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下載並解壓安裝包
創建一個文件夾
cd /usr/local
mkdir nginx
cd nginx
下載tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
或手動下載:http://nginx.org/en/download.html
解壓:tar -xvf nginx-1.13.7.tar.gz
3. 安裝nginx
//進入nginx目錄
cd /usr/local/nginx
//執行命令
./configure
//執行make命令
make
//執行make install命令
make install
4. 配置nginx.conf
配置文件啓動用戶修改爲root,不光master,worker也需要修改
打開配置文件
vim /usr/local/nginx/conf/nginx.conf
將端口號改成8089,因爲可能apeache佔用80端口,apeache端口儘量不要修改,我們選擇修改nginx端口。
localhost修改爲你服務器ip地址。
5. 啓動nginx
./nginx 啓動
./nginx -s stop 關閉
./nginx -s reload 重啓
./nginx –c /use/local/nginx/nginx-12.1/conf/nginx.conf 指定配置文件
6. 查看nginx進程是否啓動:
ps -ef | grep nginx
7. 使用外部主機連接上虛擬機訪問端口:
1)關閉虛擬機的防火牆(強烈不建議)
CentOS6及以前版本使用命令: systemctl stop iptables.service
CentOS7關閉防火牆命令: systemctl stop firewalld.service
2)放開Nginx的端口
Linux防火牆端口放行與取消https://blog.csdn.net/c_chuxue/article/details/103865685
隨後訪問該ip即可看到nginx界面。