1.將nginx放到y(tǒng)um repro庫中
執(zhí)行命令: rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.查看nginx信息
執(zhí)行命令: yum info nginx
3.使用yum安裝ngnix
執(zhí)行命令: yum install nginx
4.啟動nginx
執(zhí)行命令: systemctl start nginx
5.查看nginx運行狀態(tài)
執(zhí)行命令:systemctl status nginx
6.查看nginx版本
執(zhí)行命令: nginx -v
7.訪問nginx測試
現(xiàn)在你可以通過公網(wǎng)ip (本地可以通過 localhost /或 127.0.0.1 ) 查看nginx 服務返回的信息铡羡。
執(zhí)行命令: curl -i localhost
8.nginx配置文件
位置在/etc/nginx/,根據(jù)自己需要進行修改配置文件意鲸,此處不作介紹
執(zhí)行命令: ll /etc/nginx/
9.實踐
目的:修改服務名烦周,接著從外部訪問這個服務
操作:
a.修改nginx配置文件
vim /etc/nginx/conf.d/default.conf
修改server_name部分:server_name? yytest.com;
b.重載服務
/usr/sbin/nginx -s reload
c.從外部訪問nginx服務(192.168.10.11)
如在客戶機(192.168.10.10)的瀏覽器訪問:http://yytest.com
d.你發(fā)現(xiàn)訪問不了,原因1怎顾,你沒有在hosts文件做映射读慎;原因2,及時你在hosts文件中了映射槐雾,由于nginx服務器的80端口堵塞或防火墻沒關
e.解決辦法:
步驟一:修改客戶機(192.168.10.10)的hosts文件夭委,使用SwitchHosts工具添加 192.168.10.11? ? yytest.com
步驟二:關閉防火墻,具體下文有說明
10.nginx常用操作
啟動:
systemctl start nginx
重啟:
systemctl restart nginx
停止:
systemctl stop nginx
測試配置文件是否正常:
/usr/sbin/nginx –t
重新加載配置文件:
/usr/sbin/nginx -s reload