要添加CentOS 7 EPEL倉庫,請打開終端並使用如下命令:html
vi /etc/yum.repos.d/nginx.repo
輸入如下內容:nginx
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
保存後退出c++
如今Nginx存儲庫已經安裝在您的服務器上,使用如下yum命令安裝Nginx :centos
sudo yum install nginx
在對提示回答yes後,Nginx將在服務器上完成安裝。瀏覽器
Nginx不會自行啓動。要運行Nginx,請輸入:服務器
sudo systemctl start nginx
若是您正在運行防火牆,請運行如下命令以容許HTTP和HTTPS通訊:ui
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
您將會看到默認的CentOS 7 Nginx網頁url
若是想在系統啓動時啓用Nginx。請輸入如下命令:code
sudo systemctl enable nginx
恭喜!Nginx如今已經安裝並運行了!htm
nginx -v
nginx配置文件位置在/etc/nginx/ 修改nginx配置文件
vi /etc/nginx/conf.d/default.conf
重載服務
/usr/sbin/nginx -s reload
Nginx的安裝依賴如下文件:
1.一、安裝gcc: yum install gcc-c++ 1.2 、安裝PCRE pcre-devel: yum install -y pcre pcre-devel 1.3 、安裝zlib: yum install -y zlib zlib-devel 1.四、安裝OpenSSL: yum install -y openssl openssl-devel
http://nginx.org/en/download.html
[root@ou Downloads]# tar -xzvf nginx-1.12.2.tar.gz -C /opt
[root@ou nginx-1.12.2]# ./configure
默認生成配置信息以下
nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx modules path: "/usr/local/nginx/modules" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp"
[root@ou nginx-1.12.2]# make [root@ou nginx-1.12.2]# make install
[root@ou nginx-1.12.2]# whereis nginx nginx: /usr/local/nginx
cd /usr/local/nginx/sbin/ ./nginx ./nginx -s stop ./nginx -s quit ./nginx -s reload ./nginx -s quit:此方式中止步驟是待nginx進程處理任務完畢進行中止。 ./nginx -s stop:此方式至關於先查出nginx進程id再使用kill命令強制殺掉進程。 瀏覽器打開localhost便可訪問
ps aux|grep nginx
9.一、先中止再啓動(推薦):
對 nginx 進行重啓至關於先中止再啓動,即先執行中止命令再執行啓動命令。以下: ./nginx -s quit ./nginx
9.二、從新加載配置文件:
當 ngin x的配置文件 nginx.conf 修改後,要想讓配置生效須要重啓 nginx,使用-s reload不用先中止 ngin x再啓動 nginx 便可將配置信息在 nginx 中生效,以下: ./nginx -s reload