CentOS下编译安装Nginx服务器并修改Nginx服务器访问根目录
一、 nginx安装环境
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
该命令等效于下面4句:
1、 gcc 安装
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:
yum install gcc-c++
2、 PCRE pcre-devel 安装
PCRE(PerlCompatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
3、 zlib 安装
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
4、OpenSSL 安装
OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
二、下载nginx
1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html
2.使用wget命令下载1.10.1版本(推荐)。
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
三、安装
1、解压
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
2、配置
其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置
./configure
输出:
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
3、编译安装
make
make install
查找安装路径:"/usr/local/nginx
四、开放80端口、开放http服务,重启防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --reload
firewall-cmd --list-all #查看开放服务、端口中是否有http服务和80端口。
五、更改nginx访问根目录
安装完nginx服务器后发现nginx的根目录在 安装目录的/html/下(/usr/local/nginx/html/),但是对于部署文件来说,在该目录下是不太习惯的,我就尝试着更改nginx访问的根目录
1、更改nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
更改如下:
server {
listen 80;
server_name localhost;
location / {
root /home/ftpuser/wwwRoot; #新的根目录
index index.html index.htm index.jpg; #添加一张图片,测试用。
}
2、nginx根目录权限设置:
chmod -R 755 /home/ftpuser/wwwRoot/
3、重启nginx务器
service nginx restart
4、测试
拷贝一直张jpg格式图片到:/home/ftpuser/wwwRoot/目录下,改名为:index.jpg 。
chmod 744 /home/ftpuser/wwwRoot/index.jpg #设置所有人可读。
访问http://localhost/,图片即在网页中显示出来。
设置完成后此时访问http://localhost/XXX 即为/home/www/XXX
六、使用nginx
1 启动nginx
/usr/local/nginx/sbin/nginx
注意:执行 /usr/local/nginx/sbin/nginx,这里可以-c指定加载的nginx配置文件,如下:
/usr/local/nginx/sbin/nginx -c /xxxxx
如果不指定-c,nginx在启动时默认加载/usr/local/nginx/conf/nginx.conf文件。
2 停止nginx
/usr/local/nginx/sbin/nginx -s quit
此方式停止步骤是待nginx进程处理任务完毕进行停止。
3 重启nginx:先停止再启动
/usr/local/nginx/sbin/nginx -s quit
/usr/local/nginx/sbin/nginx

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
CentOS下用iostat -x查看磁盘的IO信息
点评 :Linux系统出现了性能问题,一般我们可以通过top.iostat,vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据 Linux系统出现了性能问题,一般我们可以通过top.iostat,vmstat等命令来查看初步定位问题。其中iostat可以给我们提供丰富的IO状态数据。 www.jb51.net iostat结果分析 [kefu@SZ-8 linux]$ iostat -x -k Linux 2.6.18-128.el5_cyou_1.0 (SZ-8.30) 09/08/2011 avg-cpu: %user %nice %system %iowait %steal %idle 16.58 0.00 2.79 0.46 0.00 80.16 Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util sda 0.06 29.28 0.22 37.14 10.21 265.68 14.77 0.02 0.51 0.15 0.55 sda1 0...
- 下一篇
新浪Linux运维工程师面试真题曝光
作为Linux运维工程师,进入大公司是开启职业新起点的关键,今天马哥linux运维及云计算智囊团的小伙伴特别分享了其在新浪面试Linux运维及云计算工程师的题目和经历,希望对广大Linux运维及云计算的求职者有一个帮助。 【招聘岗位要求】 【岗位定义】运维工程师 【岗位薪资】10K-20K 【基本要求】经验1-3年 /本科及以上 /全职 【职位描述】 1、负责服务器和应用的监控和应急反应,需要值夜班以确保有7*24小时的持续运作能力; 2、负责设计并部署相关应用平台,并提出平台的实施、运行报告; 3、负责相关故障、疑难问题排查处理,编制汇总故障、问题,定期提交汇总报告; 4、负责日常系统维护及监控,提供IT软硬件方面的服务和支持,保证系统的稳定。 【职位要求】 1、熟悉Linux和WindowsServer操作系统及相关运维技术; 2、熟悉数据传输(如kafka、scribe等)及存储(hdfs、ceph、mfs等)相关技术,并有实际运维经验; 3、了解服务器虚拟化技术(kvm、docker),实际管理运维过服务器虚拟化高可用集群; 4、了解MySQL、SQLServer等主流数据库,...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS关闭SELinux安全模块
- CentOS7设置SWAP分区,小内存服务器的救世主
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16
- 设置Eclipse缩进为4个空格,增强代码规范
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2全家桶,快速入门学习开发网站教程
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题