栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx网址服务

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx网址服务

目录

引言

一、基础服务

1、Nginx优点

2、Nginx.conf介绍(/usr/local/nginx/conf/nginx.conf)

二、访问控制

基于授权的访问控制 htpasswd是一个用于目录访问权限认证的一个工具

生成用户密码认证文件,并添加Nginx服务,给400权限

修改主配置文件相对应目录。添加认证配置项 

重启服务

总结


引言

今天给大家介绍一个目前很多公司都在用的前端页面的网址服务,是目前应用最多的服务之一,在过去我们用的比较多的是Apache,现在是Nginx,并不是说现在没有人用Apache,而是更具具体的公司环境,现在Nginx更适合大多数的公司,被广泛应用的原因也是因为它有自己独特的优点

一、基础服务

1、Nginx优点

—款高性能、轻量级Web服务软件

稳定性高,系统资源消耗低,对HTTP并发连接的处理能力高(单台物理服务器可支持30000~50 000个并发请求,具体根据实际环境情况,大约在3万)

2、Nginx.conf介绍(/usr/local/nginx/conf/nginx.conf)
#user  nobody;                     #全局配置
worker_processes  1;               #最大工作进程             

#error_log  logs/error.log;         #工作日志
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;          #pid位置


events {                            #i/o事件配置
    worker_connections  1024;        #进程最大可连接数
}

http {                                   #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;
    #tcp_nopush     on;

    #keepalive_timeout  0;                  #超时时间
    keepalive_timeout  65;

    #gzip  on;

    server {                                #服务定义
        listen       80;                    #监控端口
        server_name  localhost;             #服务名

        #charset koi8-r;                    #字符语言

        #access_log  logs/host.access.log  main;
        location / {      #正则表达式,匹配的是/usr/local/nginx/html/index.html 50x.html
            root   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;    #匹配50x.html
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {              #以php结尾的php(转义)
        #    proxy_pass   http://127.0.0.1;    #跳转页面
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000   #php端口
        #
        #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;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configurati
on    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server                               #加密方式
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

二、访问控制

1、基于授权的访问控制 htpasswd是一个用于目录访问权限认证的一个工具

-c:创建密码文件,如果文件存在,那么内容被清空中写
 

生成用户密码认证文件,并添加Nginx服务,给400权限
yum install -y httpd-tools
htpasswd -c /usr/local/nginx/passwd.db zhang
chown nginx /usr/local/nginx/passwd.db
chmod 400 /usr/local/nginx/passwd.db

修改主配置文件相对应目录。添加认证配置项 
vim /usr/local/nginx/conf/nginx.conf


		location / {                        ##添加认证配置##

	        auth_basic "secret";
			auth_basic_user_file /usr/local/nginx/passwd.db;
	
            root html;
            index index.html index.htm;}


	}
	

重启服务
nginx -t
systemctl restart nginx

总结

前面也和大家说了现在被广泛使用的是Nginx,下面就说一说它的优点

1、httpd和nginx区别,首先nginx与httpd以静态页面处理+动态页面转发的功能上比较类似,但是nginx优势在于抗高并、发轻量级、性能稳定
2、nginx的配置文件中包含的模块从全局,具体匹配的URI,分为以下几种

全局模块——在此模块中定义的内容,会生效于所有配置
http——应用于用户以http方式访问nginx这个过程

server服务——适用于通过端口、ip 、域名的访问方式的请求

location——URL www .ly.com/ index.html

3、NG并发连接能力影响因素

cup个数和本地物理服务器系统的最大文件打开数

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/299659.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号