编译环境安装yum-ygccyum-ygcc++yum-ygcc-c++yum-yinstallwget下载安装文件并解压>创建文件夹进入mkdirsoft&&cdsoft>下载依赖文件pcre,openssl,zlibwget-chttp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gzwget-chttps://www.openssl.org/source/openssl-1.0.2l.tar.gzwget-chttp://zlib.net/zlib-1.2.11.tar.gz>下载nginxwget-chttp://nginx.org/download/nginx-1.10.1.tar.gz>解压文件tar-zxvfpcre-8.39.tar.gztar-zxvfopenssl-1.0.2l.tar.gztar-zxvfzlib-1.2.11.tar.gztar-zxvfnginx-1.10.1.tar.gz创建用户和目录>新建系统账号nginxuseradd-rnginx-s/sbin/nologin-M>创建nginx需要的目录mkdir-p/var/tmp/nginx/{client_body,proxy,fastcgi,uwsgi,scgi}>递归更改所有目录chown-Rnginx/var/tmp/nginxcompilenginx-1.10.1cd~/soft/nginx-1.10.1./configure\--prefix=/usr/local/nginx\--sbin-path=/usr/sbin/nginx\--conf-path=/etc/nginx/nginx.conf\--error-log-path=/var/log/nginx/error.log\--http-log-path=/var/log/nginx/access.log\--pid-path=/var/run/nginx。pid\--lock-path=/var/lock/nginx.lock\--user=nginx\--group=nginx\--with-http_ssl_module\--with-http_realip_module\--with-http_stub_status_module\--with-http_gzip_static_module\--with-pcre=../pcre-8.39\--with-zlib=../zlib-1.2.11\--with-openssl=../openssl-1.0.2l\--with-调试\--http-client-body-temp-path=/var/tmp/nginx/client_body\--http-proxy-temp-path=/var/tmp/nginx/proxy\--http-fastcgi-temp-路径=/var/tmp/nginx/fastcgi\--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\--http-scgi-temp-path=/var/tmp/nginx/scgi\--with-streammake&&makeinstall编写脚本文件>创建文件并打开服务脚本vim/etc/init.d/nginx>编写脚本文件#!/bin/bash##nginx-这个脚本启动和停止nginx守护进程##chkconfig:-8515#description:Nginx是HTTP(S)服务器,HTTP(S)反向\#代理和IMAP/POP3代理服务器##processname:nginx#config:/etc/nginx/nginx.conf#pidfile:/var/run/nginx.pid#源函数库。./etc/rc.d/init.d/functions#源网络配置。./etc/sysconfig/network#检查网络是否正常。["$NETWORKING"="no"]&&exit0nginx="/usr/sbin/nginx"prog=$(basename$nginx)NGINX_CONF_FILE="/etc/nginx/nginx.conf"[-f/etc/sysconfig/nginx]&&。/etc/sysconfig/nginxlockfile=/var/lock/nginx.lockstart(){[-x$nginx]||退出5[-f$NGINX_CONF_FILE]||exit6echo-n"Starting$prog:"daemon$nginx-c$NGINX_CONF_FILEretval=$?echo[$retval-eq0]&&touch$lockfilereturn$retval}stop(){echo-n"Stopping$prog:"killproc$prog-QUITretval=$?echo[$retval-eq0]&&rm-f$lockfilereturn$retval}restart(){配置测试||返回$?停止睡眠1开始}reload(){配置测试||返回$?echo-n"Reloading$prog:"killproc$nginx-HUPRETVAL=$?echo}force_reload(){restart}configtest(){$nginx-t-c$NGINX_CONF_FILE}rh_status(){status$prog}rh_status_q(){rh_status>/dev/null2>&1}case"$1"instart)rh_status_q&&退出0$1;;停止)rh_status_q||退出0$1;;重启|配置测试)$1;;重新加载)rh_status_q||出口7$1;;强制重新加载)force_reload;;状态)rh_status;;condrestart|try-restart)rh_status_q||出口0;;*)echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"exit2;;esac配置nginx启动脚本>更改文件权限chmod+x/etc/init.d/nginx>添加到系统服务chkconfig--addnginx>设置系统启动chkconfignginxonstartnginxserversystemctlstartnginxstartservicestatus[root@localhostsoft]#systemctlstatusnginx.service●nginx.service-SYSV:Nginx是一个HTTP(S)服务器,HTTP(S)反向代理和IMAP/POP3代理服务器Loaded:loaded(/etc/rc.d/init.d/nginx;坏;供应商预设:禁用)活动:活动(运行)自美国东部时间星期二2017-06-1311:47:44起;22秒前文档:man:systemd-sysv-generator(8)进程:40801ExecStart=/etc/rc.d/init.d/nginxstart(code=exited,status=0/SUCCESS)MainPID:40808(nginx)内存:1.0MCGroup:/system.slice/nginx.service├─40808nginx:主进程/usr/sbin/nginx-c/etc/nginx/nginx.conf└─40809nginx:工作进程Jun1311:47:43localhost.localdomainsystemd[1]:启动SYSV:Nginx是HTTP(S)服务器、HTTP(S)反向代理和IMAP/POP3代理服务器...Jun1311:47:44localhost.localdomainnginx[40801]:启动nginx:[确定]Jun1311:47:44localhost.localdomainsystemd[1]:StartedSYSV:Nginx是一个HTTP(S)服务器、HTTP(S)反向代理和IMAP/POP3代理服务器。[root@localhostsoft]#修改nginx配置文件#运行user#usernobody;#启动进程,通常设置为等于cpu的dataworker_processes1;#全局错误日志和PID文件#error_loglogs/error.log;#error_log日志/error.log通知;#error_log日志/error.log信息;#pid日志/nginx.pid;#工作模式和连接限制事件{useepoll;worker_connections1024;}http{包括mime.types;default_type应用程序/八位字节流;log_formatmain'$remote_addr-$remote_user[$time_local]"$request"''$status$body_bytes_sent"$http_referer"''"$http_user_agent""$http_x_forwarded_for"';access_log日志/access.logmain;发送文件;#tcp_nopush上;#keepalive_timeout0;keepalive_timeout65;tcp_nodelayon;gzip上;gzip_disable"MSIE[1-6]";client_header_buffer_size128k;large_client_header_buffers4128k;服务器{听80;服务器名称www.nginx.dev;#charsetkoi8-r;access_loglogs/nginx.dev.access.logmain;位置/{root/data/www/html;indexindex.phpindex.htmlindex.htm;}#error_page404/404.html;#将服务器错误页面重定向到静态页面/50x.html#error_page500502503504/50x.html;location=/50x.html{root/data/www/html;}location~^/(images|javascript|js|css|flash|media|static)/{过期30d;}#将PHP脚本代理到侦听127.0.0.1:80的Apache##location~\.php${#proxy_passhttp://127.0.0.1;#}#将PHP脚本传递给监听127.0.0.1:9000的FastCGI服务器#location~\.php${#roothtml;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;包括fastcgi_params;}#拒绝访问.htaccess文件,如果Apache的文档根#与nginx的一致#l位置~/\.ht{全部拒绝;}}#另一个混合使用基于IP、名称和端口的配置的虚拟主机##server{#listen8000;#听某个名字:8080;#server_namesomename别名another.alias;#位置/{#根html;#索引index.htmlindex.htm;#}#}#HTTPS服务器##server{#listen443ssl;#server_name本地主机;#ssl_certificatecert.pem;#ssl_certificate_keycert.key;#ssl_session_cache共享:SSL:1m;#ssl_session_timeout5m;#ssl_ciphersHIGH:!aNULL:!MD5;#ssl_prefer_server_ciphers开启;#位置/{#根html;#索引index.htmlindex.htm;#}#}}CentOS7添加打开放80TCP端口>添加打开放配置文件的端口firewall-cmd--zone=public--add-port=80/tcp--permanent--zone=public添加时区--add-port=80/tcp添加端口--permanentpermanent>loadfirewall新建配置文件(以root身份输入以下命令,在不中断用户连接的情况下重新加载防火墙,即不丢失状态信息。)firewall-cmd--reload希望本文对您的工作和学习有所帮助。如果你觉得还不错呢?谢谢我?我的天啊!喜欢它!祝你好运!来自warnerwu于2017.06.24PM
