美文网首页
<翻译>Nginx入门

<翻译>Nginx入门

作者: ShootHzj | 来源:发表于2017-09-06 00:55 被阅读17次

    Nginx(发音自 "Engine X")是一个高性能的web服务器。Nginx可以用来当作一个web服务器,也可以作为反向代理服务其他web服务器。

    用作反向代理时,Nginx可以处理像SSL,HTTPS,Gzip,缓存头,负载均衡等事务。后台web服务器并不需要知道如何处理这些事。

    在OSX上,运行下面的命令来安装nginx

      brew install nginx
    

    在Ubuntu上,使用

    apt-get install nginx
    

    然后使用

    /etc/init.d/nginx start
    

    来启动nginx

    使用

    htop
    

    命令,在这个命令的输出,查看是否存在 nginx master进程和nginx worker进程,如果你看到那些进程存在,就证明nginx正在运行。

    如果你对nginx的配置文件做了更改,你需要重启nginx服务器

    /etc/init.d/nginx restart
    

    一旦nginx重启,新的配置文件也就生效了。

    nginx的配置文件如下:

    user www-data
    worker_process 4;
    pid /run/nginx.pid
    
    events{
      worker_connections 768;
      # multi_accept on;
    }
    
    http {
      ##
      # Basic Settings
      ##
      
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
      #server_tokens off;
      
      #server_names_hash_bucket_size 64;
      #server_name_in_redirect off;
      
      include /etc/nginx/mime.types;
      default_type application/octet-stream
    
      ##
      # Logging Settings
      ##
      
      access_log /var/log/nginx/access.log
      error_log /var/log/nginx/error.log
    
      ##
      # Gzip Settings
      ## 
      
      gzip on;
      gzip_disable "msie6";
      
      # gzip_vary on;
      #gzip_proxied any;
      #gzip_comp_level 6;
      #gzip_buffers 16 8k;
      #gzip_http_version 1.1;
      #gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    
      ##
      # nginx-naxsi config
      ##
      # Uncomment it if you installed nginx-naxsi
      ##
      
      #include /etc/nginx/naxsi_core.rules
    
      ##
      # nginx-passenger config
      ##
      # Uncomment it if you installed nginx-passenger
      ##
    
      #passenger_root /usr;
      #passenger_ruby /usr/bin/ruby;
    
      ##
      # Virtual Host Configs
      ##
    
      server {
        listene 443;
        server_name _;
        ssl on;
        ssl_certificate  certificate-bundle.crt;
        ssl_certificate_key private-key.pem
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        location {
          proxy_pass http://127.0.0.1:8080;
        }
      }
    
    所有和反向代理相关的配置都在都在server块中。
    
    listen443 代表监听443端口
    server_name _使nginx知道,所有域名匹配这个server节
    ssl on 表示Nginx打开SSL/HTTPS。
    ssl_certificate certificate-bundle.crt指向证书文件。
    ssl_certificate_key private-key.pem指向生成证书签名的私钥。
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2设置了支持何种SSL协议。
    location 使得nginx传递所有的请求给本机的8080端口。

    相关文章

      网友评论

          本文标题:<翻译>Nginx入门

          本文链接:https://www.haomeiwen.com/subject/yrzpjxtx.html