简介
centos7生命周期就省两年了 这东西可有可无 再用一下吧
centos8之后就可以直接yum install -y nginx
简单配置
cd /usr/local/src # download wget下载失败只能手动再上传 wget http://nginx.org/download/nginx-1.20.1.tar.gz tar -xvzf #预编译执行配置脚本,进行预处理 cd nginx-1. ./configure #编译并安装 make && make install #创建 nginx 软连接,全局使用 ln -sf /usr/local/nginx/sbin/nginx /usr/local/bin/nginx nginx -v # 已创建软连接 # 开机自启 centos7有点麻烦 cd /usr/lib/systemd/system/ vi nginx.service [Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target systemctl enable nginx systemctl status nginx
nginxserver属性配置(域名 根目录)
# 众所周知 nginx可以配置多个项目 每个项目可以存放多个页面 # 利用nginx的 include属性 # servername [+域名] include server /*; # 可以使用多个server #默认有一个conf.d目录 也可以自行创建 在目录下创建 a.conf, b.conf 当然代码abc别说是我教的 变量名自己想办法
# a.conf server { listen 80; server_name www.a.com; location / { root 项目地址 index index.html index.htm } } # b.conf server { listen 80; server_name www.b.com; location / { root 项目地址 index index.html index.htm } } # nginx php环境 server { listen 80 default_server; server_name www.a.com; # location / { root /usr/local/onedrive; index index.html index.php; if(!=e $request_filename){ } } location ~ \.php(.*)$ { faatcgi_pass 127.0.0.1:php:9090; faatcgi_index index.php faatcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; faatcgi_split_path_info ^((?U).+\php)(/?.+)$; faatcgi_param PATH_INFO $faatcgi_path_info; faatcgi_param SCRIPT_NAME $fastcgi_script_name; faatcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }