Ubuntu 安装nginx

1、更新Ubuntu

# add-apt-repository 仓库名称
# apt-get update
# apt-get install -y libssl1.0.2 openssl

2、安装Nginx

# apt-get install -y nginx
# apt-get install -y nginx-extras

3、设置Nginx通用配置文件

cat /etc/nginx/nginx.conf

user www-data; #ubuntu里面nginx用户名
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 1024;
    # 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;   #关闭显示nginx版本

    server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;
    ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EECDH+AESGCM:EDH+AESGCM:AES2
56+EECDH:AES256+EDH";
    ssl_ecdh_curve secp384r1; # Requires nginx >= 1.1.0
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off; # Requires nginx >= 1.5.9
    # ssl_stapling on; # Requires nginx >= 1.3.7
    ssl_stapling_verify on; # Requires nginx => 1.3.7

    ##
    # Logging Settings
    ##

    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 /data/log/nginx/access.log main;
    error_log /data/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_vary on;
    gzip_min_length 1k;
    gzip_buffers 4 32k;
    gzip_disable "msie6";
    gzip_disable "MSIE [1-6].";
    gzip_http_version 1.1;
    gzip_comp_level 3;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript application/json;
    ##
    # Proxy Headers
    ##
    include /etc/nginx/proxy.conf;   #设置代理头信息
    more_set_headers "Server: Customer Web Server Header";

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;  #配置各个站点的信息
}

4、设置Nginx代理

cat /etc/nginx/proxy.conf

proxy_redirect          off;
proxy_set_header        Host $host;
#proxy_set_header        X-Real-IP $remote_addr; #获取真实IP
proxy_set_header       X-Forwarded-For   $proxy_add_x_forwarded_for; #获取代理者的真实ip
client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   90;
proxy_send_timeout      90;
proxy_read_timeout      90;
proxy_buffer_size       4k;
proxy_buffers           4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

5、设置站点配置信息

cd /etc/nginx/sites-enabled/

upstream local_iis_80 {
    server 后端IP1:80 max_fails=2 fail_timeout=10s weight=10;
    server 后端IP2:80 max_fails=2 fail_timeout=10s weight=10;
    keepalive 45;  #防止出现nginx向后端发请求的时候连接打爆了
}

upstream local_iis_443 {
    server 后端IP1:443 max_fails=2 fail_timeout=10s weight=10;
    server 后端IP1:443 max_fails=2 fail_timeout=10s weight=10;
    keepalive 45;  #防止出现nginx向后端发请求的时候连接打爆了
}

server {
    listen 80;
    charset utf-8;

    location / {
        proxy_pass http://local_iis_80;
    }
}

server {
    listen 443 ssl http2;                 #支持http2
    charset utf-8;

    ssl_certificate /data/cert/证书.crt;
    ssl_certificate_key /data/cert/证书.key;

    location / {
        proxy_pass https://local_iis_443;
    }
}
时间: 2024-10-17 19:32:24

Ubuntu 安装nginx的相关文章

Ubuntu安装nginx

我用的是Ubuntu 16.04安装nginx. 1.输入:apt-get install build-essentialapt-get install libtool 2.安装pcre依赖库(http://www.pcre.org/)sudo apt-get updatesudo apt-get install libpcre3 libpcre3-dev 3.安装zlib依赖库(http://www.zlib.net)apt-get install zlib1g-dev 4.安装ssl依赖库a

ubuntu安装nginx pagespeed

一.自动安装 使用最新稳定版本的ngx_pagespeed自动安装依赖项并构建最新的主线版nginx,请运行: $ sudo bash <(curl -f -L -sS https://ngxpagespeed.com/install) --nginx-version latest 二.手动安装 1.安装依赖 $ sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev libxslt

ubuntu安装nginx配置反向代理服务器

安装nginx: sudo apt-get install nginx 启动nginx; sudo service nginx start 如果报了这样的错误: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)2015/01/16 15:55:46 [warn] 1973#0: the "user" direc

Ubuntu安装nginx(复制)

gcc.g++依赖库 apt-get install build-essential apt-get install libtool 安装 pcre依赖库(http://www.pcre.org/) sudo apt-get install libpcre3 libpcre3-dev 或源码安装: cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz tar -z

Ubuntu 安装 nginx

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-09/147157.htm 1.安装依赖项 sudo apt-get update sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libp

ubuntu 安装nginx redis dotnet

1 安装nginx sudo apt-get update sudo apt-get install nginx 配置文件 /etc/nginx/nginx.conf 2 安装redis sudo add-apt-repository universe sudo apt-get update sudo apt-get install redis-server 配置文件 vim /etc/redis/redis.conf 3 安装dotnet 1)在线包管理器安装 参考:https://docs.

Ubuntu安装 Nginx

一 Ubuntu(Debian)软件包安装 apt-get update apt-get install nginx Ubuntu10.04安装openssl,执行如下操作来安装openssl及其开发函数库: sudo apt-get install openssl sudo apt-get install libssl0.9.8 sudo apt-get install libssl-dev PCRE库安装 sudo apt-get update sudo apt-get install li

ubuntu安装nginx与配置

命令行安装:(当前时间为2018.11,版本为1.10.3) sudo apt-get install nginx 安装好的文件位置: /usr/sbin/nginx:主程序 /etc/nginx:存放配置文件 /usr/share/nginx:存放静态文件 /var/log/nginx:存放日志 查找Nginx启动文件路径 find / -name nginx.conf 查询nginx进程 ps -ef | grep nginx 重启nginx sudo nginx -s reload 查看是

ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library

需要安装pcre包. sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev 你可能还需要安装 sudo apt-get install openssl libssl-dev