在本文中,我们将为您详细介绍CentOS安装Nginx的两种方式的相关知识,此外,我们还会提供一些关于###centos7.4安装nginx-1.10.3###、00044-centos安装nginx
在本文中,我们将为您详细介绍CentOS 安装Nginx 的两种方式的相关知识,此外,我们还会提供一些关于###centos 7.4 安装nginx-1.10.3###、00044-centos 安装nginx、
- CentOS 安装Nginx 的两种方式
- ###centos 7.4 安装nginx-1.10.3###
- 00044-centos 安装nginx
配置 SessionFactory 的两种方式 - CentOS 5.6 安装Nginx
CentOS 安装Nginx 的两种方式
一、yum安装(推荐)
centos7
(1)使用yum安装Nginx需要包括Nginx的库,安装Nginx的库
#rpm -Uvh
(2)使用下面命令安装Nginx
#yum install Nginx
(3)启动Nginx
#service Nginx start
或
#systemctl start Nginx.service
配置文件在 /etc/Nginx/conf.d/
二、手动安装
一、安装准备
首先由于Nginx的一些模块依赖一些lib库,所以在安装Nginx之前,必须先安装这些lib库,这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以执行如下命令安装
$ yum install gcc-c++
$ yum install pcre pcre-devel
$ yum install zlib zlib-devel
$ yum install openssl openssl--devel
二、安装Nginx
安装之前,最好检查一下是否已经安装有Nginx
$ find -name Nginx
如果系统已经安装了Nginx,那么就先卸载
$ yum remove Nginx
首先进入/usr/local目录
$ cd /usr/local
从官网下载最新版的Nginx
$ wget
解压Nginx压缩包
$ tar -zxvf Nginx-1.7.4.tar.gz
会产生一个Nginx-1.7.4 目录,这时进入Nginx-1.7.4目录
$ cd Nginx-1.7.4
接下来安装,使用--prefix参数指定Nginx安装的目录,make、make install安装
$ ./configure $默认安装在/usr/local/Nginx
$ make
$ make install
如果没有报错,顺利完成后,最好看一下Nginx的安装目录
$ whereis Nginx
安装完毕后,进入安装后目录(/usr/local/Nginx)便可以启动或停止它了。
启动 /usr/local/Nginx/sbin/Nginx
重启 /usr/local/Nginx/sbin/Nginx –s reload
停止 /usr/local/Nginx/sbin/Nginx –s stop
测试配置文件是否正常 /usr/local/Nginx/sbin/Nginx –t
强制关闭 pkill Nginx
Nginx配置文件 /usr/local/Nginx/conf/Nginx.conf
###centos 7.4 安装nginx-1.10.3###
centos 7.4 安装Nginx-1.10.3
$ yum install gcc-c++
$ yum install pcre pcre-devel
$ yum install zlib zlib-devel
$ yum install openssl openssl-devel
mkdir -p /usr/local/Nginx #创建一个安装目录
cd /usr/local/Nginx #切换到创建好的目录
wget http://nginx.org/download/nginx-1.10.3.tar.gz #下载安装包
tar -zxvf Nginx-1.10.3.tar.gz #解压
cd Nginx-1.10.3 #到解压目录下编译
./configure --prefix=/usr/local/Nginx --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module
#在编译的时候可能遇到以下报错:
/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. #没有安装pcre-devel
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules,or install the OpenSSL library
into the system,or build the OpenSSL library statically from the source
with Nginx by using --with-openssl=<path> option #没有安装openssl-devel
#针对上诉的报错情况,执行下面的安装命令,然后就可以正常编译
yum -y install pcre-devel openssl openssl-devel
make && make install #安装
安装完成之后把Nginx添加成系统服务
vim /etc/init.d/Nginx #在 /etc/init.d下创建一个Nginx文件,并输入以下代码
#!/bin/bash
#chkconfig: 2345 80 90
#description:auto_run
PATH=/usr/local/Nginx
DESC="Nginx server"
NAME=Nginx
DAEMON=$PATH/sbin/$NAME
CONfigFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONfigFILE || echo -n "Nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "Nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "Nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
chmod a+x /etc/init.d/Nginx #给执行权限
chkconfig --add Nginx #注册成服务
chkconfig Nginx on #设置开机启动
添加成系统服务之后可以使用以下命令控制Nginx服务
systemctl start Nginx.service #启动Nginx服务
systemctl stop Nginx.service #停止Nginx服务
systemctl restart Nginx.service #重启Nginx服务
systemctl reload Nginx.service #重新读取Nginx配置(这个最常用,不用停止Nginx服务就能使修改的配置生效)
00044-centos 安装nginx
要安装nginx的依赖pcre
wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.44/pcre-8.44.tar.gz
tar -xvf pcre-8.44.tar.gz
cd pcre-8.44
#安装编译
./configure
这里出错:
configure: error: no acceptable C compiler found in $PATH
需要安装GCC软件套件
yum install gcc
安装后,再运行: ./configure
这里继续出错:
configure: error: Invalid C++ compiler or C++ compiler flags
安装:
yum install -y gcc-c++
安装后,再运行: ./configure
到这里,OK。
make && make install
#查看pcre版本
pcre-config --version
开始安装nginx:
wget https://nginx.org/download/nginx-1.20.0.tar.gz
tar -xvf nginx-1.20.0.tar.gz
cd nginx-1.20.0
#编译安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/home/pcre-8.44
这里出错:./configure: error: SSL modules require the OpenSSL library.
解决方法:执行以下命令:
yum -y install openssl openssl-devel
再执行上个安装命令,OK。
make && make install
#查看版本
/usr/local/nginx/sbin/nginx -v
安装完毕。
启动命令:
/usr/local/nginx/sbin/nginx (无参数) 启动
/usr/local/nginx/sbin/nginx -s stop (-s stop)关闭
/usr/local/nginx/sbin/nginx -s reload (-s reload)重启
浏览器输入ip:80, 即可访问。
查看防火墙:
systemctl status firewalld.service
systemctl stop firewalld.service(停止防火墙)
systemctl start firewalld.service(打开防火墙)
开放端口:
firewall-cmd --zone=public --add-port=10001/tcp --permanent
firewall-cmd --zone=public --add-port=10002/tcp --permanent
firewall-cmd --reload
配置 SessionFactory 的两种方式
第一种方式,一步一步艰难的配置
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mappingResources">
<list>
<value>cn/itcast/spring/hiberante/transaction/domain/Person.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
</value>
</property>
</bean>
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
第二种方式,导入 hibernate 的配置文件
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:cn/itcast/spring/hibernate/transaction/config/hibernate.cfg.xml</value>
</property>
</bean>
<bean id="personDao"
class="cn.itcast.spring.hibernate.transaction.dao.impl.PersonDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
CentOS 5.6 安装Nginx
在/usr目录下执行命令下载最新Nginx源代码:
wget http://nginx.org/download/nginx-1.2.0.tar.gz
解压后可以看到nginx-1.2.0目录:
tar zxvf nginx-1.2.0.tar.gz
安装PCRE库
yum -y install pcre-devel
安装openssl库
yum -y install openssl openssl-devel
生成make file文件:
./configure --prefix=/usr/nginx
结果要仔细看一下,有些很重要的信息:
creating objs/Makefile Configuration summary + using system PCRE library + OpenSSL library is not used + md5: using system crypto library + sha1: using system crypto library + using system zlib library nginx path prefix: "/usr/nginx" nginx binary file: "/usr/nginx/sbin/nginx" nginx configuration prefix: "/usr/nginx/conf" nginx configuration file: "/usr/nginx/conf/nginx.conf" nginx pid file: "/usr/nginx/logs/nginx.pid" nginx error log file: "/usr/nginx/logs/error.log" nginx http access log file: "/usr/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"
比如pid 文件,error log文件,access log文件等等。
现在编译和安装:
make make install
进入/usr/nginx/sbin目录下,可以执行nginx程序启动。
如果要修改端口,修改/usr/nginx/conf/nginx.conf文件,比如:
server { listen 8081;
原文链接: http://blog.csdn.net/sheismylife/article/details/7526910
关于CentOS 安装Nginx 的两种方式的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于###centos 7.4 安装nginx-1.10.3###、00044-centos 安装nginx、
本文标签: