zoukankan      html  css  js  c++  java
  • Ubuntu 下安装 Nginx_1.12.0及简单使用

    1.下载 key并添加: http://nginx.org/keys/nginx_signing.key

    $ sudo wget http://nginx.org/keys/nginx_signing.key
    $ sudo apt-key add nginx_signing.key
    

    2.在 /etc/apt/sources.list 文件中加入下面两行:

    deb http://nginx.org/packages/ubuntu/ codename nginx
    deb-src http://nginx.org/packages/ubuntu/ codename nginx

    3.执行更新安装:

    $ apt-get update
    $ apt-get install nginx
    

    出现错误:dpkg: error processing archive /var/cache/apt/archives/nginx_1.12.0-1~precise_amd64.deb
    解决办法:

    $ sudo dpkg -i --force-overwrite /var/cache/apt/archives/nginx_1.12.0-1~precise_amd64.deb
    $ sudo apt-get -f install nginx
    $ nginx -v
    nginx version: nginx/1.12.0
    

    Beginner's Guide

    nginx is read as 'engine x'.
    By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.

    Starting, Stopping, and Reloading Configuration

    $ service nginx start
    $ nginx -s signal
    

    Where signal may be one of the following:

    • stop -- fast shutdown
    • quit -- graceful shutdown
    • reload -- reloading the configuration file
    • reopen -- reopening the log files

    The process ID of the nginx master process is written, by default, to the nginx.pid in the directory /usr/local/nginx/logs or /var/run.

    $ kill -s QUIT 1628
    $ ps -ax | grep nginx    # get the list of all running nginx processes
    

    Configuration File's Structure

    Example Configuration:

    user www www;
    worker_processes 2;
    
    error_log /var/log/nginx-error.log info;
    
    events {
        use kqueue;
        worker_connections 2048;    #this is a comment.
    }
    

    Serving Static Content

    http {
        server {
            location / {
                root /data/www;
            }
    
            location /images/ {
                root /data;
            }
        }
    }
    

    In case something does not work as expected, you may try to find out the reason in acces.log and error.log files in the directory /usr/local/nginx/logs or /var/log/nginx.

    Setting Up a Simple Proxy Server

    server {
        location / {
            proxy_pass http://localhost:8080/;
        }
    
        location ~ .(gif|jpg|png)$ {    # A regular expression should be preceded with ~
            root /data/images
        }
    }
    

    Setting Up FastCGI Proxying

    server {
        location / {
            fastcgi_pass localhost:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param QUERY_STRING $query_string;
        }
    
        location ~ .(gif|jpg|png)$ {
            root /data/images;
        }
    }
    
  • 相关阅读:
    东方财富炒股公式
    centos8安装MySQL8——通过yum
    官网下载工具时。各种不同后缀名称的区别。
    线上不停机部署mysql主从
    店员任务项目总结
    JS到PHP使用RSA算法进行加密通讯
    无锁同步-JAVA之Volatile、Atomic和CAS
    无锁同步-C++11之Atomic和CAS
    浅谈一个网页打开的全过程(涉及DNS、CDN、Nginx负载均衡等)
    SQLServer数据库卡,内存吃不上去,系统资源用不上
  • 原文地址:https://www.cnblogs.com/liuliu3/p/7060363.html
Copyright © 2011-2022 走看看