系統(tǒng)基礎(chǔ)環(huán)境:virtualbox下CentOS-Minimal-1810
1安裝方法一:源碼編譯安裝
基礎(chǔ)環(huán)境 centos7.6 mini
目錄:/usr/local/src
1、安裝前準(zhǔn)備(根據(jù)各軟件最新版本信息更改url)
下載nginx、openssl、zlib、pcre
cd /usr/local/src
wget http://nginx.org/download/nginx-1.10.2.tar.gz
wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
2安裝(順序不要錯(cuò))
安裝make
yum -y install gcc automake autoconf libtool make
安裝gcc編譯環(huán)境
# yum install gcc-c++
安裝pcre
# tar zxvf pcre-8.43.tar.gz
# cd pcre-8.40
# ./configure && make && make install
安裝openssl:
tar zxvf openssl-fips-2.0.10.tar.gz
cd openssl-fips-2.0.10
./config && make && make install
安裝zlib
tar zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
安裝nginx
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure && make && make install
這樣安裝完成后,nginx的路徑為/usr/local/nginx/sbin/nginx
2安裝方法二:
查看CentOS的版本
cat /etc/redhat-release
添加資源庫
在 CentOS 系統(tǒng)上安裝 Nginx ,得先去添加一個(gè)資源庫:
vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
安裝nginx
yum -y install nginx
使用命令
systemctl stop nginx.service #停止nginx服務(wù)
systemctl start nginx.service #打開nginx服務(wù)
systemctl restart nginx.service #重啟nginx服務(wù)
systemctl status nginx.service #查看nginx服務(wù)狀態(tài)
驗(yàn)證nginx安裝成果:
開啟nginx,
cd /usr/local/nginx/sbin
./nginx
或
systemctl start nginx.service
驗(yàn)證:
curl http://localhost
應(yīng)該能輸出Welcome to nginx的html文件,說明安裝啟動(dòng)成功。
開啟外部訪問
centos7默認(rèn)開啟了防火墻模塊firewalld,可以查看一下是否開啟
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Mon 2019-03-18 10:12:46 EDT; 34s ago
Docs: man:firewalld(1)
Main PID: 3618 (firewalld)
CGroup: /system.slice/firewalld.service
└─3618 /usr/bin/python -Es /usr/sbin/firewalld --nofork...
Mar 18 10:12:46 localhost.localdomain systemd[1]: Starting firewal...
Mar 18 10:12:46 localhost.localdomain systemd[1]: Started firewall...
Hint: Some lines were ellipsized, use -l to show in full.
或者:
[root@localhost ~]# firewall-cmd --state
running
關(guān)閉firewalld,然后在虛擬機(jī)外可以訪問
systemctl stop firewalld #關(guān)閉
systemctl start firewalld #打開
systemctl restart firewalld #重啟
systemctl disable firewalld #關(guān)閉開機(jī)啟動(dòng)
systemctl enable firewalld #開機(jī)啟動(dòng)

image.png