centos7搭建lnmp编译安装nginx【二】

来源:互联网 发布:知行理工忘记密码 编辑:程序博客网 时间:2024/05/20 04:26
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

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 ServerNGINX_HOME=/usr/local/nginxNGINX_SBIN=$NGINX_HOME/sbin/nginxNGINX_CONF=$NGINX_HOME/conf/nginx.confNGINX_PID=$NGINX_HOME/logs/nginx.pidNGINX_NAME="Nginx". /etc/rc.d/init.d/functionsif [ ! -f $NGINX_SBIN ]then    echo "$NGINX_NAME startup: $NGINX_SBIN not exists! "    exitfistart() {    $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 1esac



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

0 0
原创粉丝点击