一、安装环境



Nginx下载地址:nginx zlib下载页面:zlib pcre下载页面:pcre


二、编译安装: #useradd nginx -s /sbin/nologin #yum install gcc-c++ -y #./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --user=nginx --group=nginx --with-pcre=/opt/pcre-8.42 --with-zlib=/opt/zlib-1.2.11 --with-http_geoip_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module #make && make install


三、启动脚本(/lib/systemd/system/nginx.service) [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target

[Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true

[Install] WantedBy=multi-user.target


四、启动服务: systemctl enable nginx systemctl start nginx systemctl reload nginx systemctl restart nginx 五、配置ssl 六、http跳转https 七、其他配置

注: nginx中root与alias指令之间的区别: root和alias都可以定义在location模块中,都是用来指定请求资源的真实路径,例如: root指令 location /c/ { root /a/b; }

访问http://www.liheng1815.xyz/a/index.html ------------>真实资源路径:/a/b/c/index.html 真实的路径是root指定的值加上location制动的值。

alias指令 alias正如其名,是location的路径别名,不管location怎么写,资源的真实路径都是alias指定的路径,例如: location /c/ { alias /a/b/; }

访问http://www.liheng1815.xyz/a/index.html ------------>真实资源路径:/a/b/index.html