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