欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

LNMP平台服务详解、安装与使用

最编程 2024-08-09 19:48:52
...
******(1)安装必要组件 [root@centos7-007 ~]# mount /dev/cdrom /media/cdrom/ mount: /dev/sr0 写保护,将以只读方式挂载 [root@centos7-007 ~]# yum -y install pcre-devel zlib-devel 。。。。。。 完毕! ******(2)创建nginx的用户 [root@centos7-007 ~]# useradd -M -s /sbin/nologin nginx ******(3)上传源码包,配置、编译、并安装 [root@centos7-007 ~]# ll 总用量 964 -rw-------. 1 root root 1220 9月 3 18:16 anaconda-ks.cfg -rw-r--r-- 1 root root 980831 1月 27 23:03 nginx-1.12.0.tar.gz [root@centos7-007 ~]# tar xf nginx-1.12.0.tar.gz -C /usr/src/ [root@centos7-007 ~]# cd /usr/src/nginx-1.12.0/ [root@centos7-007 nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module —————————————————————————————————————华丽分割线——————————————————————————————————————— --with-http_stub_status_module 支持状态统计,便于查看服务器的连接信息 ————————————————————————————————————————————————————————————————————————————————————— [root@centos7-007 nginx-1.12.0]# make && make install ******(4)验证安装 [root@centos7-007 nginx-1.12.0]# ls /usr/local/nginx/ conf html logs sbin ******(5)创建软连接,优化执行路径 [root@centos7-007 nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ [root@centos7-007 nginx-1.12.0]# ls -l /usr/local/sbin/ |grep nginx lrwxrwxrwx 1 root root 27 1月 27 23:06 nginx -> /usr/local/nginx/sbin/nginx ******(6)编辑配置文件,可以先备份一份 [root@centos7-007 nginx-1.12.0]# mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak [root@centos7-007 nginx-1.12.0]# vim /usr/local/nginx/conf/nginx.conf (重新写一份配置文件) 写入 worker_processes 1; events { use epoll; worker_connections 4096; } 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; keepalive_timeout 65; server { listen 80; server_name www.benet.com; charset utf-8; location / { root html; index index.html index.php; } location /status { stub_status on; access_log off; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } 保存退出 ******(7)检查配置文件语法是否正确 [root@centos7-007 nginx-1.12.0]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok (ok说明语法正确) nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful ******(8)安装killall命令 [root@centos7-007 nginx-1.12.0]# yum -y install psmisc 。。。。。。 完毕! ******(9)编写nginx的启动脚本,添加nginx为系统服务 [root@centos7-007 nginx-1.12.0]# vim /etc/init.d/nginx 写入 #!/bin/bash # chkconfig: - 99 20 # description: Nginx Server Control Script NP="/usr/local/nginx/sbin/nginx" NPF="/usr/local/nginx/logs/nginx.pid" case "$1" in start) $NP; if [ $? -eq 0 ] then echo "nginx is starting!! " fi ;; stop) kill -s QUIT $(cat $NPF) if [ $? -eq 0 ] then echo "nginx is stopping!! " fi ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $NPF) if [ $? -eq 0 ] then echo "nginx config file is reload! " fi ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0 保存退出 [root@centos7-007 nginx-1.12.0]# chmod +x /etc/init.d/nginx (添加可执行权限) [root@centos7-007 nginx-1.12.0]# chkconfig --add nginx (添加nginx为系统服务) ******(10)测试nginx是否能正常使用 [root@centos7-007 nginx-1.12.0]# /etc/init.d/nginx start (开启) nginx is starting!! [root@centos7-007 nginx-1.12.0]# curl 127.0.0.1 (访问本地循环地址,发现可以正常访问) <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html> ******(11)关闭nginx [root@centos7-007 nginx-1.12.0]# /etc/init.d/nginx stop (关闭) nginx is stopping!! [root@centos7-007 nginx-1.12.0]# netstat -anpt | grep nginx (查看端口确认已经关闭) [root@centos7-007 nginx-1.12.0]# cd [root@centos7-007 ~]# 至此Ngnix网站服务搭建完成

推荐阅读