centos7搭建lnmp编译安装nginx【二】
2017-01-05 09:12
696 查看
1.官网下载安装包nginx-1.8.0.tar.gz
http://nginx.org/download/nginx-1.8.0.tar.gz
2.通过命令解压文件
[root@localhost share]# tar -zxvf nginx-1.8.0.tar.gz
3.执行配置:
[root@localhost nginx-1.8.0]# ./configure
4.编译安装
[root@localhost nginx-1.8.0]# make&&make install
注:配置如果执行不成功,一般需要安装相应的库:PCRE,zlib,ssl
5.默认安装到/usr/local/nginx/,进入安装的目录
[root@localhost nginx-1.8.0]# cd /usr/local/nginx/
6.测试是否安装成功
启动:
[root@localhost sbin]# /usr/local/nginx/sbin/nginx
打开浏览器,访问本地页面,如果出现Welcome to nginx!就说明成功了
注:如果不成功,请查看80端口是否被占用
[root@localhost sbin]# netstat -antlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2704/nginx: master
7.设置php页面可访问,本人的简单配置如下:
[root@localhost conf]# cat nginx.conf
本人的网站根目录放在/opt/www,域名访问设置为 web.iqter.local;
8.设置全局环境变量nginx,执行
[root@localhost ~]# vim /etc/profile
文件最后添加
export PATH="/usr/local/nginx/sbin:$PATH"
立即生效:
[root@localhost ~]# source /etc/profile
9.设置开机自启动
a.进入目录
[root@localhost ~]# cd /etc/init.d/
b.编辑文件,添加内容
[root@localhost init.d]# vim nginx
c.保存后,增加文件执行权限
[root@localhost init.d]# chmod a+x nginx
e.开启nginx系统服务
[root@localhost init.d]# chkconfig nginx on
10.如果局域网其他网站不能访问,请在hosts文件加对应IP映射域名
192.168.1.99 web.iqter.local
并在centos增加防火墙访问80端口
[root@localhost init.d]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@localhost init.d]# firewall-cmd --reload
========================
注:不同版本设置防火墙端口访问命令不同
centos7
使用这些命令来永久打开一个新端口(如TCP/80)。
centos6
使用iptables的第一条命令可以通过防火墙开启一个新TCP/UDP端口。为了永久保存修改过的规则,还需要第二条命令。
chkconfig使用
chkconfig --list #列出所有的系统服务
chkconfig --add httpd #增加httpd服务
chkconfig --del httpd #删除httpd服务
chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig --list #列出系统所有的服务启动情况
chkconfig --list mysqld #列出mysqld服务设置情况
chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级
查看系统支持打开的文件数
[root@localhost init.d]# ulimit -n
1024
随手摘录的技术博客
http://my.oschina.net/zyc1016/blog/138574
https://blog.linuxeye.com/421.html
http://nginx.org/download/nginx-1.8.0.tar.gz
2.通过命令解压文件
[root@localhost share]# tar -zxvf nginx-1.8.0.tar.gz
3.执行配置:
[root@localhost nginx-1.8.0]# ./configure
4.编译安装
[root@localhost nginx-1.8.0]# make&&make install
注:配置如果执行不成功,一般需要安装相应的库:PCRE,zlib,ssl
5.默认安装到/usr/local/nginx/,进入安装的目录
[root@localhost nginx-1.8.0]# cd /usr/local/nginx/
6.测试是否安装成功
启动:
[root@localhost sbin]# /usr/local/nginx/sbin/nginx
打开浏览器,访问本地页面,如果出现Welcome to nginx!就说明成功了
注:如果不成功,请查看80端口是否被占用
[root@localhost sbin]# netstat -antlp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2704/nginx: master
7.设置php页面可访问,本人的简单配置如下:
[root@localhost conf]# cat nginx.conf
user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { 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; server_name web.iqter.local; root /opt/www/; location / { index index.php; } location ~ ^/.+\.php { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; } } }
本人的网站根目录放在/opt/www,域名访问设置为 web.iqter.local;
8.设置全局环境变量nginx,执行
[root@localhost ~]# vim /etc/profile
文件最后添加
export PATH="/usr/local/nginx/sbin:$PATH"
立即生效:
[root@localhost ~]# source /etc/profile
9.设置开机自启动
a.进入目录
[root@localhost ~]# cd /etc/init.d/
b.编辑文件,添加内容
[root@localhost init.d]# vim nginx
#!/bin/sh #chkconfig: 2345 85 15 # description:Nginx Server NGINX_HOME=/usr/local/nginx NGINX_SBIN=$NGINX_HOME/sbin/nginx NGINX_CONF=$NGINX_HOME/conf/nginx.conf NGINX_PID=$NGINX_HOME/logs/nginx.pid NGINX_NAME="Nginx" . /etc/rc.d/init.d/functions if [ ! -f $NGINX_SBIN ] then echo "$NGINX_NAME startup: $NGINX_SBIN not exists! " exit fi start() { $NGINX_SBIN -c $NGINX_CONF ret=$? if [ $ret -eq 0 ]; then action $"Starting $NGINX_NAME: " /bin/true else action $"Starting $NGINX_NAME: " /bin/false fi } stop() { kill `cat $NGINX_PID` ret=$? if [ $ret -eq 0 ]; then action $"Stopping $NGINX_NAME: " /bin/true else action $"Stopping $NGINX_NAME: " /bin/false fi } restart() { stop start } check() { $NGINX_SBIN -c $NGINX_CONF -t } reload() { kill -HUP `cat $NGINX_PID` && echo "reload success!" } relog() { kill -USR1 `cat $NGINX_PID` && echo "relog success!" } case "$1" in start) start ;; stop) stop ;; restart) restart ;; check|chk) check ;; status) status -p $NGINX_PID ;; reload) reload ;; relog) relog ;; *) echo $"Usage: $0 {start|stop|restart|reload|status|check|relog}" exit 1 esac
c.保存后,增加文件执行权限
[root@localhost init.d]# chmod a+x nginx
e.开启nginx系统服务
[root@localhost init.d]# chkconfig nginx on
10.如果局域网其他网站不能访问,请在hosts文件加对应IP映射域名
192.168.1.99 web.iqter.local
并在centos增加防火墙访问80端口
[root@localhost init.d]# firewall-cmd --zone=public --add-port=80/tcp --permanent
[root@localhost init.d]# firewall-cmd --reload
========================
注:不同版本设置防火墙端口访问命令不同
centos7
使用这些命令来永久打开一个新端口(如TCP/80)。
$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent $ sudo firewall-cmd --reload
centos6
使用iptables的第一条命令可以通过防火墙开启一个新TCP/UDP端口。为了永久保存修改过的规则,还需要第二条命令。
$ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT $ sudo service iptables save
chkconfig使用
chkconfig --list #列出所有的系统服务
chkconfig --add httpd #增加httpd服务
chkconfig --del httpd #删除httpd服务
chkconfig --level httpd 2345 on #设置httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态
chkconfig --list #列出系统所有的服务启动情况
chkconfig --list mysqld #列出mysqld服务设置情况
chkconfig --level 35 mysqld on #设定mysqld在等级3和5为开机运行服务,--level 35表示操作只在等级3和5执行,on表示启动,off表示关闭
chkconfig mysqld on #设定mysqld在各等级为on,“各等级”包括2、3、4、5等级
查看系统支持打开的文件数
[root@localhost init.d]# ulimit -n
1024
随手摘录的技术博客
http://my.oschina.net/zyc1016/blog/138574
https://blog.linuxeye.com/421.html
相关文章推荐
- 开发人员学Linux(5):CentOS7编译安装Nginx并搭建Tomcat负载均衡环境
- Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛 推荐
- 开发人员学Linux(5):CentOS7编译安装Nginx并搭建Tomcat负载均衡环境
- CentOS7最小化安装下源码编译搭建LAMP, LNMP环境及搭建discuz论坛
- LNMP搭建2:Nginx编译安装
- 源码编译安装,搭建LNMP环境(Linux+Nginx+MySQL+PHP)
- CentOS 6.5 LNMP环境搭建 编译安装Nginx
- CentOS 7源码编译安装PHP5.6和Nginx1.7.9及MySQL(搭建LNMP环境)
- 基于CentOS 6.8平台最新源代码包编译安装LNMP环境搭建(Nginx+MySQL+PHP)
- lnmp(nginx1.4.5+mysql5.5+php5.4)编译版搭建论坛
- Ubuntu 搭建LNMP环境图文教程 安装Nginx服务器
- CentOS 5.6(X64)下编译安装LNMP平台(Nginx1.0.4+PHP5.3.6+Mysql5.5.12)
- 编译安装LNMP红帽6.4(64位)Nginx1.4.1+mysql5.6.+php5.4.4
- CentOS6.x编译安装LNMP(Linux+Nginx+Mysql+PHP)
- CentOS 6.3 编译安装搭建LNMP
- CentOS 5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装Wordpress、Discuz
- 生产环境Centos LNMP编译安装nginx-1.6 MySQL-5.6 php-5.5
- 编译安装LNMP环境,搭建wordpress博客
- ubuntu12.04 虚拟机 编译安装nginx 1.3.6 搭建支持flv mp4 流媒体服务器
- CentOS-6.4 源码包编译安装LNMP +Discuz开源论坛(mysql-5.6.14 +PHP-5.4.21+nginx-1.4.2)