nginx安装 #查看操作系统版本 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) #查看内核版本和64位还是32位 [[email protected] ~]# uname -a Linux master1 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux #关闭selinux #临时关闭 [[email protected] sbin]# getenforce Enforcing [[email protected] sbin]# setenforce 0 [[email protected] sbin]# getenforce Permissive #永久关闭 [[email protected] sbin]# sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config #关闭iptables #临时关闭 [[email protected] sbin]# systemctl stop firewalld.service #开机不启动(永久关闭) [[email protected] sbin]# systemctl disable firewalld.service Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service. Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service. #yum进行依赖解决 [[email protected] ~]# yum install openssl openssl-devel -y #openssl使用https服务的时候要用此模块 [[email protected] ~]# yum install pcre pcre-devel -y #使nginx支持URI重写的rewrite模块 #安装nginx依赖检查 [[email protected] ~]# rpm -qa openssl openssl-devel pcre pcre-devel pcre-8.32-15.el7_2.1.x86_64 openssl-devel-1.0.1e-60.el7_3.1.x86_64 pcre-devel-8.32-15.el7_2.1.x86_64 openssl-1.0.1e-60.el7_3.1.x86_64 #获得安装介质 [[email protected] home]# mkdir -p /home/wangyp/tools [[email protected] home]# cd /home/wangyp/tools/ [[email protected] tools]# wget http://nginx.org/download/nginx-1.12.0.tar.gz #创建用户 [[email protected] tools]# useradd nginx -s /sbin/nologin -M [[email protected] tools]# tar -zxf nginx-1.12.0.tar.gz [[email protected] nginx-1.12.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.0/ --with-http_stub_status_module --with-http_ssl_module checking for OS + Linux 3.10.0-514.el7.x86_64 x86_64 checking for C compiler ... not found ./configure: error: C compiler cc is not found ##需要安装编译器 ##yum进行编译器的安装 [[email protected] nginx-1.12.0]# yum -y install gcc gcc-c++ autoconf automake make ##--user --group指定用户 --prefix指定安装路径 --with-http激活两个模块(一个监控的,一个ssl支持的)可通过[[email protected] nginx-1.12.0]# ./configure --help进行查看 enable ngx_http_stub_status_module enable ngx_http_ssl_module [[email protected] nginx-1.12.0]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.12.0/ --with-http_stub_status_module --with-http_ssl_module [[email protected] nginx-1.12.0]# make [[email protected] nginx-1.12.0]# make install [[email protected] nginx-1.12.0]# ln -s /application/nginx-1.12.0 /application/nginx ##检查并启动nginx [[email protected] sbin]# ./nginx -t nginx: the configuration file /application/nginx-1.12.0//conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.12.0//conf/nginx.conf test is successful [[email protected] sbin]# /application/nginx/sbin/nginx [[email protected] sbin]# lsof -i :80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 13236 root 6u IPv4 159539 0t0 TCP *:http (LISTEN) nginx 13237 nginx 6u IPv4 159539 0t0 TCP *:http (LISTEN) [[email protected] sbin]# ps -ef | grep nginx root 13236 1 0 10:26 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx nginx 13237 13236 0 10:26 ? 00:00:00 nginx: worker process root 13241 10440 0 10:27 pts/0 00:00:00 grep --color=auto nginx ##测试 wget&curl两个命令都可以 [[email protected] sbin]# wget 127.0.0.1 --2017-06-27 10:32:33-- http://127.0.0.1/ 正在连接 127.0.0.1:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:612 [text/html] 正在保存至: “index.html” 100%[===============================================================================================================================>] 612 --.-K/s 用时 0s 2017-06-27 10:32:33 (86.8 MB/s) - 已保存 “index.html” [612/612]) [[email protected] sbin]# 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>
[[email protected] conf]# more nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name www.loveurself.org; location / { root html/www; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name bbs.loveurself.org; location / { root html/bbs; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
压力测试工具:
webenche
时间: 2024-10-05 04:58:24