| 
1.介绍
×
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册  
 Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器。其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好,中国大陆使用nginx的网站有:百度、京东、新浪、网易、腾讯、淘宝等。
 Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。
 官网:https://nginx.org/
 2.Nginx-命令(手动安装限定)
 
 1.查看版本
 2.检查配置文件
 3.启动
 4.停止
 停止之后,我们可以查看nginx的进程:5.重新加载
 
 当修改了Nginx配置文件后,需要重新加载才能生效,可以使用下面命令重新加载配置文件:3.环境变量配置
 
 在上述我们在使用nginx命令在进行服务的启动、停止、重新加载时,都需要用到一个指令nginx,而这个指令是在nginx/sbin目录下的,我们每一次使用这个指令都需要切换到sbin目录才可以,使用相对繁琐。那么我们能不能在任意目录下都可以执行该指令来操作nginx呢?答案是可以的,配置nginx的环境变量即可。
 打开/etc/profile文件, 在PATH环境变量中增加nginx的sbin目录,如下:
 修改完配置文件之后,需要执行 source /etc/profile 使文件生效。 接下来,我们就可以在任意目录下执行nginx的指令了复制代码ecpot PATH=/usr/local/nginx/sbin:$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
#安装
 
 手动安装
 
 1.安装依赖包
 
 由于nginx是基于c语言开发的,所以需要安装c语言的编译环境,及正则表达式库等第三方依赖库。
 2.下载Nginx安装包复制代码yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
 以1.16.1版本为例
 复制代码wget https://nginx.org/download/nginx-1.16.1.tar.gz
wget:3.解压nginx压缩包wget命令用来从指定的URL下载文件。wget非常稳定,它在带宽很窄的情况下和不稳定网络中有很强的适应性,如果是由于网络的原因下载失败,wget会不断的尝试,直到整个文件下载完毕。如果是服务器打断下载过程,它会再次联到服务器上从停止的地方继续下载。
 
 
 4.配置Nginx编译环境复制代码tar -zxvf nginx-1.16.1.tar.gz
 复制代码./configure --prefix=/usr/local/nginx
----prefix 指定的目录,就是我们安装Nginx的目录。5.编译&安装
 docker安装
 
 1.docker拉取nginx镜像
 2.创建映射容器的文件目录
 
 创建配置文件目录
 复制代码mkdir -p /mydata/nginx/conf/
复制代码mkdir -p /mydata/nginx/conf.d/
授予权限复制代码mkdir -p /mydata/nginx/log/
复制代码chmod 777 /mydata/nginx/conf/
复制代码chmod 777 /mydata/nginx/conf.d/
3.在/mydata/nginx/conf/中创建nginx.conf文件复制代码chmod 777 /mydata/nginx/log/
 4.在/mydata/nginx/conf.d/中创建default.conf文件复制代码user  nginx;worker_processes  auto; error_log  /var/log/nginx/error.log notice;pid        /var/run/nginx.pid;  events {    worker_connections  1024;}  http {    include       /etc/nginx/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  /var/log/nginx/access.log  main;     sendfile        on;    #tcp_nopush     on;     keepalive_timeout  65;     #gzip  on;     include /etc/nginx/conf.d/*.conf;}
 5.创建容器复制代码server {    listen       80;    listen  [::]:80;    server_name  localhost;     #access_log  /var/log/nginx/host.access.log  main;     location / {        root   /usr/share/nginx/html;        index  index.html index.htm;    }     #error_page  404              /404.html;     # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   /usr/share/nginx/html;    }     # proxy the PHP scripts to Apache listening on 127.0.0.1:80    #    #location ~ \.php$ {    #    proxy_pass   http://127.0.0.1;    #}     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    #    #location ~ \.php$ {    #    root           html;    #    fastcgi_pass   127.0.0.1:9000;    #    fastcgi_index  index.php;    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;    #    include        fastcgi_params;    #}     # deny access to .htaccess files, if Apache's document root    # concurs with nginx's one    #    #location ~ /\.ht {    #    deny  all;    #}}
 复制代码docker run -p 80:80 --name nginx \--restart=always \-v /mydata/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \-v /mydata/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \-v /mydata/nginx/log:/var/log/nginx \-d nginx
-d:后台运行-p:端口映射
 --name:指定容器名称
 -v:数据卷映射
 --restart:重启容器方式
 
 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
 |