本次实验实现目的:

安装Nginx,Nginx开启目录浏览、下载功能,开机默认启动;咐件自带开机启动脚本、重启脚本;

1、关闭SELINUX

查看获取SELinux的状态:

[root@localhost ~]# getenforce

[root@localhost ~]# vim /etc/selinux/config

SELINUX=disabled #默认为:enforcing

2、添加开放nginx端口号

查看获取iptables的状态:

[root@localhost ~]# service iptables status

在防火墙IPtables 添加nginx监听的端口80;

[root@localhost ~]# vim /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

:wq #保存

重启IPtables

[root@localhost ~]# service iptables restart

确认安装成功并启动:nginx监听的端口80;

[root@localhost ~]# netstat -na |grep :80

3、下载软件包

[root@localhost ~]# cd /usr/local/src/

[root@localhost src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz

[root@localhost src]# wget http://nginx.org/download/nginx-1.3.8.tar.gz

4、安装pcre 让安装Nginx支持rewrite 方便以后所需

方法1:

[root@localhost ~]# yum install pcre*

方法2:

[root@localhost src]# tar zxvf pcre-8.31.tar.gz

[root@localhost src]# cd pcre-8.31

[root@localhost pcre-8.31]# ./configure

[root@localhost pcre-8.31]# make;make install

5、安装nginx

将nginx-1.3.8.tar.gz传到/usr/local/src(安装需要编译的软件,最好放到这个目录下)。

[root@localhost src]# tar zxvf nginx-1.3.8.tar.gz

[root@localhost src]# cd nginx-1.3.8

[root@localhost nginx-1.3.8]# ./configure --prefix=/usr/local/nginx

[root@localhost nginx-1.3.8]# make;make install

6、安装Apache

[root@localhost ~]# yum install http*

[root@localhost ~]# service httpd restart

7、修改httpd配置文件

查找httpd.conf配置文件路径

[root@localhost ~]#find / -name httpd.conf

修改端口号:

修改端口号目的:httpd与nginx端口冲突,必须改其中一个端口号;

[root@localhost ~]#vim /etc/httpd/conf/httpd.conf

Listen 8080 #默认为:80,修改为:8080

8、nginx配置文件测试

[root@localhost ~]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

测试成功!

9、Nginx启动

[root@localhost ~]# /usr/local/nginx/sbin/nginx

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

出现这些东西,说明服务已经启动。

然后在ie中访问你服务器的ip,出现这个就安装成功了!

http://0.0.0.0

10、查看日志

[root@localhost ~]# tail /usr/local/nginx/logs/access.log

11、开启全站所有目录浏览功能

创建目录:

[root@localhost ~]# mkdir /webshare

编辑配置文件,在http{下面添加以下内容

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

http {

autoindex on; #开启nginx目录浏览功能

autoindex_exact_size off; #文件大小从KB开始显示

autoindex_localtime on; #显示文件修改时间为服务器本地时间

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

# '$status $body_bytes_sent "$http_referer" '

# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

gzip on;

server {

listen 80; #Nginx端口号

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

#root html;

root /webshare; #/webshare网站根目录路径

autoindex on;

index index.html index.htm;

}

:wq #保存,退出

12、nginx开机自动启动

启动脚本

第一步、先运行命令关闭nginx

[root@localhost ~]# sudo kill `cat /usr/local/nginx/logs/nginx.pid`

第二步、编辑启动脚本、重启脚本(咐件有脚本,上传到/etc/init.d/目录下)

[root@localhost ~]# vim /etc/init.d/nginx

添加输入以下内容:

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig: - 85 15

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \

# proxy and IMAP/POP3 proxy server

# processname: nginx

# config: /usr/local/nginx/conf/nginx.conf

# pidfile: /usr/local/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

[ -x $nginx ] || exit 5

[ -f $NGINX_CONF_FILE ] || exit 6

echo -n $"Starting $prog: "

daemon $nginx -c $NGINX_CONF_FILE

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

killproc $prog -QUIT

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

configtest || return $?

stop

start

}

reload() {

configtest || return $?

echo -n $"Reloading $prog: "

killproc $nginx -HUP

RETVAL=$?

echo

}

force_reload() {

restart

}

configtest() {

$nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

status $prog

}

rh_status_q() {

rh_status >/dev/null 2>&1

}

case "$1" in

start)

rh_status_q && exit 0

$1

;;

stop)

rh_status_q || exit 0

$1

;;

restart|configtest)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

exit 2

esac

:wq 保存退出

第三步、设置/etc/init.d/nginx 为777权限

[root@localhost ~]# chmod 777 /etc/init.d/nginx

第四步、设置开机默认启动

[root@localhost ~]# /sbin/chkconfig nginx on

检查一下

[root@localhost ~]# sudo /sbin/chkconfig --list nginx

nginx 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

完成!

之后,就可以使用以下命令了;

service nginx start #开启

service nginx stop #停止

service nginx restart #重启

service nginx reload #重新加载

/etc/init.d/nginx start #开启

/etc/init.d/nginx stop #停止

/etc/init.d/nginx restart #重启

/etc/init.d/nginx reload #重新加载

然后在ie中访问你服务器的ip,出现这个就安装成功了!

http://0.0.0.0

上传一些资料到服务器上,客户端可以通IE下载;上传方法有多种,参考:

SecureCRT 安装上传(rz)和下载(sz) http://yanghuawu.blog.51cto.com/2638960/1009591

13、nginx关闭进程命令

方法一

停止操作是通过向nginx进程发送信号来进行的

步骤1:查询nginx主进程号

[root@localhost ~]# ps -ef | grep nginx

在进程列表里 面找master进程,它的编号就是主进程号了。

步骤2:发送信号

从容停止Nginx:

[root@localhost ~]# kill -QUIT 主进程号

快速停止Nginx:

[root@localhost ~]# kill -TERM 主进程号

强制停止Nginx:

[root@localhost ~]# kill -9 nginx

方法二

[root@localhost ~]# yum install lsof

[root@localhost ~]# lsof -i :80

[root@localhost ~]#kill -9 进程号

14、安装过程中问题

---------------------------------------------------------------------

有报错:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

解决方法:

[root@localhost nginx-1.3.8]# yum install pcre*

---------------------------------------------------------------------

安装完成:

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/local/nginx/sbin/nginx"

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"

----------------------------------------------------------------------

本文出自 “运维工作生涯” 博客,请务必保留此出处http://yanghuawu.blog.51cto.com/2638960/1055329

转载于:https://blog.51cto.com/linushai/1080534

CentOS 6.3安装Nginx开启目录浏览、下载功能相关推荐

  1. nginx服务器网站目录浏览,Nginx开启目录浏览功能 | 系统运维

    说明:Nginx在默认安装好之后,是禁止目录浏览的,如下图所示 系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接 http://www. ...

  2. nginx开启目录浏览,解决中文乱码问题

    nginx开启目录浏览,解决中文乱码问题 参考文章: (1)nginx开启目录浏览,解决中文乱码问题 (2)https://www.cnblogs.com/maqingyuan/p/9132690.h ...

  3. Nginx开启目录浏览文件和文件夹

    为了更直观的查看和下载文件,可以用nginx做成目录浏览 设置全局的在http里设置保证和server同级 http{autoindex on; #开启nginx目录浏览功能autoindex_exa ...

  4. ubuntu 安装nginx 并开启目录浏览功能

    首先 如果安装apache  应该卸载 sudo apt-get --purge remove apache2 sudo apt-get --purge remove apache2.2-common ...

  5. 如何在 CentOS 7 上安装 Nginx

    本文首发:开发指南:如何在 CentOS 7 上安装 Nginx Nginx 读作 engine x, 是一个免费的.开源的.高性能的 HTTP 和反向代理服务,主要负责负载一些访问量比较大的站点. ...

  6. nginx下目录浏览及其验证功能、版本隐藏等配置记录

    工作中常常有写不能有网页下载东西的需求,在Apache下搭建完成后直接导入文件即可达到下载/显示文件的效果; 而Nginx的目录列表功能默认是关闭的,如果需要打开Nginx的目录列表功能,需要手动配置 ...

  7. centos 7 在线安装nginx 查看gcc,pcre,zlib,openssl 等依赖是否安装

    之前整理过centos 7 离线安装nginx的步骤 在线安装相对操作就简易多了 查看安装nginx需要的依赖是否已安装 没安装yum指令在线安装即可 我使用的是centos7.6版本 安装的ngin ...

  8. Centos 7编译安装Nginx

    Centos 7编译安装Nginx 第一步:防火墙开启80端口或关闭防火墙 第二步:下载Nginx的压缩包 第三步:安装Nginx所需要的环境 第四步:解压Nginx的压缩包 第五步:配置Nginx ...

  9. centOS 7 离线安装 nginx 1.21

    NGINX 离线安装 centOS 7 离线安装 nginx 1.21.6 准备环境 1.离线 centOS 7 2.nginx 安装文件 (nginx-***.tar.gz 已放到下面的链接中,请自 ...

最新文章

  1. 电脑壁纸励志_励志壁纸 | 要乖 要长大 要努力 要不负众望
  2. 云服务器上安装jboss_jboss的使用和安装
  3. 动态库、静态库、运行时库、引入库之间的区别
  4. C/C++代码优化方法
  5. 抖音封杀小猪佩奇,一年赚100亿的“社会人”得罪了谁?
  6. php解析定时任务格式,php 实现定时任务简单实现
  7. 集群故障处理之处理思路以及健康状态检查(三十二)
  8. 整理CVPR2012感兴趣的文章
  9. linux 占用缓存前10_MySQL基于linux的内存分析
  10. 推荐几款好用的CRM
  11. python画龙猫_微信小程序支付demo,后端使用python
  12. lintcode:Plus One 加一
  13. 杭电多校第三次 Problem A. Ascending Rating(单调队列)
  14. java读取txt文件乱码问题
  15. 启动计算机键盘没反应,如何解决电脑开机显示屏和键盘无反应
  16. Target host is not specified解决方案
  17. 在react-native fetch中 then res res.json 是什么意思
  18. 循环队列front==rear
  19. 执念斩长河专栏线代概率--目录
  20. 由错误<note: candidate expects 1 argument, 0 provided>引发的思考

热门文章

  1. VTK:Shaders之MarbleShaderDemo
  2. VTK:InfoVis之WordCloud
  3. VTK:几何对象之ParametricSuperToroid
  4. OpenCV Gunnar Farneback的密集光流算法(附完整代码)
  5. QT的QSharedDataPointer类的使用
  6. QT的QDesignerContainerExtension类的使用
  7. c语言 动态内存相关函数
  8. parzen窗估计如何进行结果分析_实现一下模式识别(一)Parzen窗估计
  9. linux制作openssl rpm,CentOS 7 定制 OpenSSL RPM 包
  10. mysql输入错误怎样更正_HotDB MySQL 篇| MySQL 源码系列的补充与更正