Linux 安装Nginx

在centos 或ubuntu中 安装 nginx 步骤总结

1.下载

wget https://nginx.org/download/nginx-1.12.1.tar.gz

2.安装必须配置
centos

yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel


ubuntu

apt-get install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

3.配置

以下命令中 起用了ssl与realip这两个模块(这是常用模块,最好都起用)

--prefix 指定安装目录

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-pcre

4.安装

make && make install

5.卸载

make uninstall && make clean


6.nginx 命令

查看帮助 nginx -h
启动命令 ./sbin/nginx 
重新加载 nginx -s reload
重新启动 nginx -s stop

7.nginx配置 ssl
复制证书文件到conf文件夹

 server {
        listen       443 ssl;
        server_name  localhost;
        
        ssl                  on;
        ssl_certificate      证书.crt;
        ssl_certificate_key  证书.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;
        }
}

8.nginx配置反向代理
在server节点下 (与location并齐) 追加

location /webapp2/{
    proxy_pass http://localhost:9000/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Server $host;
}
原文地址:https://www.cnblogs.com/liuxm2017/p/9626814.html