1、安装依赖
yum install gcc pcre-devel zlib-devel -y
2、配置Nginx的软件源
vim /etc/yum.repos.d/nginx.repo
2.1、nginx.repo内容
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3、安装Nginx(一般都是最新版)
yum -y install nginx
4、其他
rpm -q nginx(版本)
rpm -ql nginx(目录结构)
5、检查安装的插件,是否支持https协议(其他的插件可以自行百度)
nginx -V(安装的插件)
==============================
ginx version: nginx/1.22.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
6、一些命令
ps -ef |grep nginx(查看进程)
systemctl start nginx(启动)
systemctl restart nginx(重启)
nginx -t -c /etc/nginx/nginx.conf(添加conf文件然后判断是否有错误)
7、关于HTTPS反代理的配置
注意没有/var/www/html可以创建
mkdir -p /var/www/html
并设置
chmod 777 /var/www/html -R
上传的vue项目或者静态资源建议打包成zip
切换普通用户
useradd XXX(用户名)
su xxx(用户名)
将vue.zip上传到/var/www/html
使用普通用户解压
mkdir -p vue
unzip -d vue.zip vue(将vue.zip解压到vue文件夹下面)
这样避免nginx由于目录权限问题无法访问
su root
输入密码
vim /etc/nginx/conf.d/xx.conf
修改location的root
/var/www/html/vue
vim /etc/nginx/conf.d/xx.conf
============================================
配置如下
server{
listen 80;
listen 443 ssl;
server_name www.xxx.xxx;#访问的域名
keepalive_timeout 70;
ssl_certificate xxx.cer; #ssl证书
ssl_certificate_key xxx.key;#ssl 密钥
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
location / {
root /var/www/html;#vue或静态html的目录。
index index.html;# 设置首页为index.html
}
}