小白兔晒黑了

导航

 

1 下载文件

http://nginx.org/

创建文件夹

mkdir nginx
cd nginx

进入创建的文件夹
根据自己需要下载合适版本

nginx的Mainline version、Stable version、Legacy version的版本区别:

Nginx官网提供了三个类型的版本
Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老版本的稳定版

 

 

 

 

wget  http://nginx.org/download/nginx-1.18.0.tar.gz

 2 安装必要插件

yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

上次元数据过期检查:2:54:53 前,执行于 2020年11月09日 星期一 22时58分35秒。
软件包 gcc-8.3.1-5.el8.0.2.x86_64 已安装。
软件包 pcre-8.42-4.el8.x86_64 已安装。
软件包 pcre-devel-8.42-4.el8.x86_64 已安装。
软件包 zlib-1.2.11-16.el8_2.x86_64 已安装。
软件包 zlib-devel-1.2.11-16.el8_2.x86_64 已安装。
软件包 openssl-1:1.1.1c-15.el8.x86_64 已安装。
软件包 openssl-devel-1:1.1.1c-15.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!

说下这几个的作用

gcc 它可以编译 C,C++,Ada,Object C和Java等语言

pcre pcre-devel pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库

zlib zlib-devel zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装

openssl openssl-devel openssl是web安全通信的基石,没有openssl,可以说我们的信息都是在裸奔

3 解压下载好的文件

tar -zxvf nginx-1.18.0.tar.gz

 4 编译与安装

mkdir /usr/local/nginx
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx

这句话的意思是指定安装路径
--prefix=/usr/local/nginx

编译

make

安装

make install

5 启动

进入到安装nginx目录下面的sbin

cd /usr/local/nginx/sbin

启动命令

./nginx

 6 查看端口

netstat -ntlp

 浏览器打开 0.0.0.0:80

 

参考

https://blog.csdn.net/qq_29443327/article/details/106504652

配置控制台与备份文件

init.d/nginx

vim /etc/init.d/nginx

 

  1 #!/bin/sh
  2 #
  3 # chkconfig: 2345 10 20
  4 #nginx - this script starts and stops the nginx daemon 
  5 # 
  6 # chkconfig:   - 85 15 
  7 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 
  8 #               proxy and IMAP/POP3 proxy server 
  9 # processname: nginx 
 10 # config:      /etc/nginx/nginx.conf 
 11 # config:      /etc/sysconfig/nginx 
 12 # pidfile:     /var/run/nginx.pid 
 13 
 14 # Source function library. 
 15 . /etc/rc.d/init.d/functions 
 16 
 17 # Source networking configuration. 
 18 . /etc/sysconfig/network 
 19 
 20 # Check that networking is up. 
 21 [ "$NETWORKING" = "no" ] && exit 0 
 22 
 23 nginx="/usr/local/nginx/sbin/nginx" 
 24 prog=$(basename $nginx) 
 25 
 26 NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" 
 27 
 28 [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx 
 29 
 30 lockfile=/var/lock/subsys/nginx 
 31 
 32 start() { 
 33     [ -x $nginx ] || exit 5 
 34     [ -f $NGINX_CONF_FILE ] || exit 6 
 35     echo -n $"Starting $prog: " 
 36     daemon $nginx -c $NGINX_CONF_FILE 
 37     retval=$? 
 38     echo 
 39     [ $retval -eq 0 ] && touch $lockfile 
 40     return $retval 
 41 } 
 42 
 43 stop() { 
 44     echo -n $"Stopping $prog: " 
 45     killproc $prog -QUIT 
 46     retval=$? 
 47     echo 
 48     [ $retval -eq 0 ] && rm -f $lockfile 
 49     return $retval 
 50 killall -9 nginx 
 51 } 
 52 
 53 restart() { 
 54     configtest || return $? 
 55     stop 
 56     sleep 1 
 57     start 
 58 } 
 59 
 60 reload() { 
 61     configtest || return $? 
 62     echo -n $"Reloading $prog: " 
 63     killproc $nginx -HUP 
 64 RETVAL=$? 
 65     echo 
 66 } 
 67 
 68 force_reload() { 
 69     restart 
 70 } 
 71 
 72 configtest() { 
 73 $nginx -t -c $NGINX_CONF_FILE 
 74 } 
 75 
 76 rh_status() { 
 77     status $prog 
 78 } 
 79 
 80 rh_status_q() { 
 81     rh_status >/dev/null 2>&1 
 82 } 
 83 
 84 case "$1" in 
 85     start) 
 86         rh_status_q && exit 0 
 87     $1 
 88         ;; 
 89     stop) 
 90         rh_status_q || exit 0 
 91         $1 
 92         ;; 
 93     restart|configtest) 
 94         $1 
 95         ;; 
 96     reload) 
 97         rh_status_q || exit 7 
 98         $1 
 99         ;; 
100     force-reload) 
101         force_reload 
102         ;; 
103     status) 
104         rh_status 
105         ;; 
106     condrestart|try-restart) 
107         rh_status_q || exit 0 
108             ;; 
109     *)    
110       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 
111         exit 2 
112 
113 esac
View Code

 参考 https://www.cnblogs.com/codelives/p/13825145.html

chmod a+x /etc/init.d/nginx

 

原始nginx.conf数据

vim /usr/local/nginx/conf/nginx.conf
  1 #user  nobody;
  2 worker_processes  1;
  3 
  4 #error_log  logs/error.log;
  5 #error_log  logs/error.log  notice;
  6 #error_log  logs/error.log  info;
  7 
  8 #pid        logs/nginx.pid;
  9 
 10 
 11 events {
 12     worker_connections  1024;
 13 }
 14 
 15 
 16 http {
 17     include       mime.types;
 18     default_type  application/octet-stream;
 19 
 20     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
 21     #                  '$status $body_bytes_sent "$http_referer" '
 22     #                  '"$http_user_agent" "$http_x_forwarded_for"';
 23 
 24     #access_log  logs/access.log  main;
 25 
 26     sendfile        on;
 27     #tcp_nopush     on;
 28 
 29     #keepalive_timeout  0;
 30     keepalive_timeout  65;
 31 
 32     #gzip  on;
 33 
 34     server {
 35         listen       80;
 36         server_name  localhost;
 37 
 38         #charset koi8-r;
 39 
 40         #access_log  logs/host.access.log  main;
 41 
 42         location / {
 43             root   html;
 44             index  index.html index.htm;
 45         }
 46 
 47         #error_page  404              /404.html;
 48 
 49         # redirect server error pages to the static page /50x.html
 50         #
 51         error_page   500 502 503 504  /50x.html;
 52         location = /50x.html {
 53             root   html;
 54         }
 55 
 56         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 57         #
 58         #location ~ \.php$ {
 59         #    proxy_pass   http://127.0.0.1;
 60         #}
 61 
 62         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 63         #
 64         #location ~ \.php$ {
 65         #    root           html;
 66         #    fastcgi_pass   127.0.0.1:9000;
 67         #    fastcgi_index  index.php;
 68         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 69         #    include        fastcgi_params;
 70         #}
 71 
 72         # deny access to .htaccess files, if Apache's document root
 73         # concurs with nginx's one
 74         #
 75         #location ~ /\.ht {
 76         #    deny  all;
 77         #}
 78     }
 79 
 80 
 81     # another virtual host using mix of IP-, name-, and port-based configuration
 82     #
 83     #server {
 84     #    listen       8000;
 85     #    listen       somename:8080;
 86     #    server_name  somename  alias  another.alias;
 87 
 88     #    location / {
 89     #        root   html;
 90     #        index  index.html index.htm;
 91     #    }
 92     #}
 93 
 94 
 95     # HTTPS server
 96     #
 97     #server {
 98     #    listen       443 ssl;
 99     #    server_name  localhost;
100 
101     #    ssl_certificate      cert.pem;
102     #    ssl_certificate_key  cert.key;
103 
104     #    ssl_session_cache    shared:SSL:1m;
105     #    ssl_session_timeout  5m;
106 
107     #    ssl_ciphers  HIGH:!aNULL:!MD5;
108     #    ssl_prefer_server_ciphers  on;
109 
110     #    location / {
111     #        root   html;
112     #        index  index.html index.htm;
113     #    }
114     #}
115 
116 }
View Code

 

posted on 2020-11-10 01:49  小白兔晒黑了  阅读(391)  评论(0编辑  收藏  举报