centos8上安装nginx
參考自 https://www.jianshu.com/p/9b2dd37a5af9? ;
【1】安裝步驟
step1)安裝nginx
sudo yum install -y nginxstep2)啟動(dòng)nginx服務(wù)
-- 開機(jī)自啟動(dòng) sudo systemctl enable nginx -- 開啟nginx 服務(wù) sudo systemctl start nginxstep3)查看nginx狀態(tài)
sudo systemctl status nginxstep4)查看本機(jī)ip地址
sudo hostname -I | awk '{print $1}'如ip地址為 192.168.163.204 ;
step5)window機(jī)器上訪問? 192.168.163.204, 無法訪問;
step6)顯然防火墻關(guān)閉該端口被訪問權(quán)限,需要打開
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload# 開通8080訪問權(quán)限 firewall-cmd --zone=public --add-port=8080/tcp --permanent# 重載防火墻配置 firewall-cmd --reloadstep7)再次訪問成功
【2】nginx管理命令
- 1)sudo systemctl status nginx : 查看nginx狀態(tài);
- 2)sudo systemctl stop nginx : 關(guān)閉nginx服務(wù);
- 3) sudo systemctl start nginx : 啟動(dòng)或重啟 nginx服務(wù);
- 4) sudo systemctl reload nginx : 若修改了配置,如反向代理,重新加載配配置而不必重啟;
- 5)sudo systemctl? disable nginx :禁止開機(jī)自啟動(dòng);
- 6)sudo systemctl enable nginx? : 開機(jī)自啟動(dòng);?
【補(bǔ)充】nginx安裝完成后, 其配置文件在? /etc/nginx/nginx.conf?
[root@localhost nginx]# pwd /etc/nginx [root@localhost nginx]# ls conf.d fastcgi_params mime.types scgi_params win-utf default.d fastcgi_params.default mime.types.default scgi_params.default fastcgi.conf koi-utf nginx.conf uwsgi_params fastcgi.conf.default koi-win nginx.conf.default uwsgi_params.defaultnginx可執(zhí)行腳本在
[root@localhost sbin]# which nginx /usr/sbin/nginx【3】nginx腳本命令
[root@localhost sbin]# nginx -v // 查看版本號(hào) nginx version: nginx/1.14.1 [root@localhost sbin]# ps -ef | grep nginx // 查看nginx進(jìn)程是否開啟 root 11913 1 0 22:21 ? 00:00:00 nginx: master process /usr/sbin/nginx nginx 11921 11913 0 22:21 ? 00:00:00 nginx: worker process nginx 11922 11913 0 22:21 ? 00:00:00 nginx: worker process root 11984 1511 0 22:34 pts/0 00:00:00 grep --color=auto nginx [root@localhost sbin]# [root@localhost sbin]# nginx -s stop // 關(guān)閉nginx 服務(wù) [root@localhost sbin]# [root@localhost sbin]# ps -ef | grep nginx root 11991 1511 0 22:35 pts/0 00:00:00 grep --color=auto nginx [root@localhost sbin]# [root@localhost sbin]# [root@localhost sbin]# nginx // 啟動(dòng)nginx 服務(wù) [root@localhost sbin]# [root@localhost sbin]# ps -ef | grep nginx root 11993 1 0 22:35 ? 00:00:00 nginx: master process nginx nginx 11994 11993 0 22:35 ? 00:00:00 nginx: worker process nginx 11995 11993 0 22:35 ? 00:00:00 nginx: worker process root 11997 1511 0 22:35 pts/0 00:00:00 grep --color=auto nginx [root@localhost sbin]# [root@localhost sbin]# nginx -s reload // 重新加載nginx配置 [root@localhost sbin]# [root@localhost sbin]#【4】nginx結(jié)構(gòu)說明
1)所有Nginx配置文件都位于/etc/nginx/目錄中。
2)Nginx配置:主要配置文件是/etc/nginx/nginx.conf。為每個(gè)域創(chuàng)建一個(gè)單獨(dú)的配置文件使服務(wù)器易于維護(hù)。Nginx服務(wù)器阻止文件必須以結(jié)尾.conf并存儲(chǔ)在/etc/nginx/conf.d目錄中。您可以根據(jù)需要擁有任意數(shù)量的服務(wù)器塊。
3)遵循標(biāo)準(zhǔn)命名約定是一個(gè)好習(xí)慣。例如,如果域名是,mydomain.com則配置文件應(yīng)命名為mydomain.com.conf;如果在域服務(wù)器塊中使用可重復(fù)的配置段,則最好將這些段重構(gòu)為片段。
4)Nginx日志:日志文件(access.log和error.log)位于/var/log/nginx/目錄中。建議有不同access和error日志文件每個(gè)服務(wù)器模塊。
5)您可以將域文檔的根目錄設(shè)置為所需的任何位置。webroot的最常見位置包括:
- /home/<user_name>/<site_name>? :
- /var/www/<site_name>? : 存儲(chǔ)不同網(wǎng)站的資源 ;
- /var/www/html/<site_name>? :存放靜態(tài)資源 html,css,js;
- /opt/<site_name>? :
- /usr/share/nginx/html? : 靜態(tài)html文件的位置;
總結(jié)
以上是生活随笔為你收集整理的centos8上安装nginx的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 英雄祭电视剧演员表(全部演员及剧情介绍)
- 下一篇: centos8安装并启动tomcat9