介紹:
Nginx是一個HTTP和反向代理的服務(wù)器蹄咖,也是一個IMAP/POP/SMTP服務(wù)器
安裝過程
環(huán)境:ubuntun 16.04
1,安裝 apt -get install nginx(非root用戶命令行前面添加 sudo),安裝不成功或者安裝之前請跟新軟件源sudo apt-get update 如果繼續(xù)不成功渊季,請手動安裝相關(guān)依賴
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
CentOS:
1.配置阿里云的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo [http://mirrors.aliyun.com/repo/Centos-7.repo](http://mirrors.aliyun.com/repo/Centos-7.repo)
2.配置阿里云的epel
wget -O /etc/yum.repos.d/epel.repo [http://mirrors.aliyun.com/repo/epel-7.repo](http://mirrors.aliyun.com/repo/epel-7.repo)
3.yum安裝nginx
[root@db01 ~]# yum install nginx -y
4.啟動nginx
[root@db01 ~]# systemctl start nginx.service
5.nginx默認路徑
(1) Nginx配置路徑:/etc/nginx/
(2) PID目錄:/var/run/nginx.pid
(3) 錯誤日志:/var/log/nginx/error.log
(4) 訪問日志:/var/log/nginx/access.log
(5) 默認站點目錄:/usr/share/nginx/html
6.nginx命令
systemctl start nginx.service ####啟動nginx
systemctl restart nginx.service ####重啟ngingx
systemctl enable nginx.service ####設(shè)置開機自啟動
最后還可以使用請使用下載安裝包的方式安裝
2,查看其是否啟動 ps aus|grep nginx
3,查看配件文件進行設(shè)置 文件位置在/etc/nginx文件夾下面
在進行配置之前最好將配置文件備份一下账胧。備份文件cp nginx.conf nginx.conf.backup或者 mv nginx.conf nginx.conf.backup
4,配置文件 vim nginx.conf (在nginx http里面設(shè)置負載均衡)
在瀏覽器里面輸入服務(wù)器地址 出現(xiàn)nginx則表示配置成功
常用命令命令
nginx -t -c nginx.conf #檢驗配置文件是否正確 顯示 xxx is ok則表示配置文件沒問題
sudo nginx -c /etc/nginx/nginx.conf #開啟 在ubuntun上料身,nginx必須為全路徑
sudo nginx -s reload #重啟
kill -hup 進程號 #使用重啟命令重啟
nginx -s stop # 快速關(guān)閉 此方式相當于先查出nginx進程id再使用kill命令強制殺掉進程。不太友好
nginx -s quit #從容停止
ps aux|grep nginx kill -quit 進程號 #查到nginx的進程號胰锌,然后停止
相關(guān)
sudo vim hosts 域名解析
27.0.0.1 localhost #域名解析 127.0.0.1 www.liangpeng888.com#本機ip 綁定域名. 公網(wǎng) 自動解析 域名骗绕。
參考:
https://blog.51cto.com/13747009/2163199
https://blog.csdn.net/weixin_33939380/article/details/87382783