安装依赖包

安装make:yum -y install gcc automake autoconf libtool make
安装g++:yum -y install gcc gcc-c++
安装pcre和pcre-devel:yum install -y pcre pcre-devel
安装zlib zlib提供了很多压缩和解方式,nginx需要zlib对http进行gzip:yum install -y zlib zlib-devel
( 报错的话可以这样yum install -y zlib zlib-devel --setopt=protected_multilib=false )
安装openssl openssl是一个安全套接字层密码库,nginx要支持https,需要使用openssl:yum install -y openssl openssl-devel
 

安装Nginx

进入nginx目录下:cd nginx-1.17.6/
安装Nginx:
./configure --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module 
make && make install
查看nginx的安装目录: whereis nginx(一般是在/usr/local/nginx)
 

环境变量配置

打开系统环境变量设置:vim /etc/profile 
输入红色字体部分:

NGINX_HOME=/usr/local/nginx
export PATH=${NGINX_HOME}/sbin:${PATH} 
使设置生效: source /etc/profile
 
nginx -V 
查看已存在的模块,返回以下:

nginx version: nginx/1.17.6
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

配置nginx.conf

nginx的配置目录:/usr/local/nginx/conf/

启动nginx:nginx -c /usr/local/nginx/conf/nginx.conf

查看并编辑nginx.conf:

vim nginx.conf

listen:监听端口改为8089(或其他,80端口需要备案)

server_name:站点域名(默认本机ip,可以改为自定义域名如:www.test.com)

root:站点根目录(html--》/usr/local/nginx/html)

保存更改:“:wq”

重启nginx使生效:nginx -s reload

检查是否重启成功:ps aux | grep nginx

重启不成功:“kill -9  进程id ”或者“ nginx -s stop ”

需要kill两个进程,否则端口被占用无法启动成功

浏览器访问:

在Nginx上配置多个站点

1、在nginx.conf 目录下创建文件夹:mkdir conf.d

2、拷贝当前nginx.conf到新文件夹目录下:cp nginx.conf conf.d/site1.conf

3、编辑site1.conf:

 server {
listen 8081;
server_name www.site1.com; location / {
root html;
index index.html index.htm;
} location /error/ {
alias /sylvia/ErrorPages/;
} location /ErrorPages/ {
alias /sylvia/ErrorPages/;
internal;
} error_page 400 /ErrorPages/HTTP400.html;
error_page 401 /ErrorPages/HTTP401.html;
error_page 402 /ErrorPages/HTTP402.html;
error_page 403 /ErrorPages/HTTP403.html;
error_page 404 /ErrorPages/HTTP404.html;
error_page 500 /ErrorPages/HTTP500.html;
error_page 501 /ErrorPages/HTTP501.html;
error_page 502 /ErrorPages/HTTP502.html;
error_page 503 /ErrorPages/HTTP503.html; }

引入alias,创建虚拟目录。(参考:https://www.cnblogs.com/kevingrace/p/6187482.html

4、编辑根配置nginx.conf

在http{}里面最后一行添加:include conf.d/*.conf;

5、重启nginx

浏览器访问:域名+端口+path

最新文章

  1. ORACLE数据库的导入及导出
  2. TFS强制解除签入签出锁定
  3. ORACLE PL/SQL编程详解
  4. linux 文档处理命令
  5. 根据关键词kill进程
  6. php 添加redis扩展(二)
  7. COM口,串行通讯端口,RS-232接口 基础知识
  8. js的内置对象
  9. 在Simplicity Studio下创建适用于EFR32的工程项目
  10. 微信小程序测试
  11. SQL 快速生成不重复的卡号
  12. NgDL:【第二周】NN基础
  13. 获取webpart方法以及连接字符串记录
  14. Crazy Shopping(拓扑排序+完全背包)
  15. Mongodb 安装 和 启动
  16. 修改UIView的默认Layer后,修改View的值会动态修改Layer的值
  17. PmExceptionMapper.xml 20160712
  18. 设置 IE 默认模式为 IE8
  19. Unity3D 5中增加WebGL 播放插件
  20. Python WSGI v1.0 中文版(转)

热门文章

  1. Nginx核心流程及模块介绍
  2. Unity Ruby's Adventure 第二步
  3. SpringCloud断路器(Hystrix)
  4. Python类中的self的作用
  5. VisualStudio编译不生成xml、pdb文件的方法
  6. js-03-if条件判断
  7. FCC---CSS Flexbox: Use the flex-direction Property to Make a Row
  8. jquery 实现只能选中一个checkbox,选中当前的去除上一个
  9. 【Beta阶段】第十周Scrum会议
  10. 打通 DevOps 任督二脉 ,CODING 2.0 制品库全新上线