centos8部署nginx
Nginx 部署
1.創(chuàng)建 www用戶, UID、GID 皆是 501,通過cat /etc/passwd,檢查是否存在www用戶
~]# groupadd -g 501 www
~]# useradd -u 501 -g www www
~]# cat /etc/passwd
2.下載相應(yīng)版本
~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
3.解壓到/usr/local/src
~]# tar -zxvf nginx-1.16.1.tar.gz -C /usr/local/src
4.安裝依賴包,然后進(jìn)入到目錄進(jìn)行編譯安裝
~]#yum install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
~]# cd /usr/local/src/nginx-1.16.1
~]# ./configure --user=www --group=www --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_v2_module --prefix=/usr/local/webserver/nginx
~]# make && make install
5.創(chuàng)建sites目錄–sites目錄放每個(gè)項(xiàng)目的配置文件
~]# cd /usr/local/webserver/nginx/conf/
~]# mkdir sites
~]# vim /usr/local/webserver/nginx/conf/nginx.conf
文件開頭添加:
user www;
文件中差不多末尾的那里引入:
include sites/*.conf
6.設(shè)置nginx環(huán)境變量,并加載環(huán)境變量
~]# vim /etc/profile.d/nginx.sh
export NGINX_HOME=’/usr/local/webserver/nginx’
export PATH=PATH:PATH:PATH:NGINX_HOME/sbin
注意:$PATH 符號(hào)
~]# . /etc/profile.d/nginx.sh
7.校驗(yàn)nginx,
~]# nginx -t
重啟—每次添加配置文件后都要重啟nginx
~]# nginx -s reload
8.設(shè)置好nginx開機(jī)自啟
~]# vim /etc/rc.d/rc.local
/usr/local/webserver/nginx/sbin/nginx
~]#chmod +x /etc/rc.d/rc.local
9.上面提到的添加某個(gè)項(xiàng)目配置文件
~]# cd /usr/local/webserver/nginx/conf/
~]# vim 域名.conf
配置文件內(nèi)容:主要修改域名和項(xiàng)目目錄
server {
listen 80;
server_name yuepengcheng.club;
index index.html index.htm;
root /www/wwwroot/qipan1.zhijiatechnology.xyz;
location = /favicon.ico {
log_not_found off;
access_log off;
break;
}
}
!!!!!!!!!!!!!!!!!!!!!!!一定要重啟!!!!!!!!!!!!!!!!!!!!!!
配置完:nginx -t
重啟:nginx -s reload
綁定多個(gè)域名的時(shí)候直接以空格分開就好。
一定要開放80端口:-------------------------------------------------
firewall-cmd --zone=public --add-port=80/tcp --permanent
開放之后重啟:
firewall-cmd --reload
查看:
firewall-cmd --zone=public --list-ports
新服務(wù)器第一時(shí)間看下防火墻,可能需要關(guān)閉防火墻
centos7:
查看防火墻
systemctl status firewalld.service
關(guān)閉防火墻
systemctl stop firewalld.service
總結(jié)
以上是生活随笔為你收集整理的centos8部署nginx的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端性能优化:Add Expires h
- 下一篇: centos8部署Django项目---