centos7 编译安装和启动.停止https://www.cnblogs.com/xingyunblog/p/9072553.html
1.安装和启动
一.安装nginx
1.下载 wget http://nginx.org/download/nginx-1.9.15.tar.gz,安装 四个依赖库 yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
2.解压 tar -zxvf nginx.tar.gz
3./configure [--prefix] 配置可以指定安装路径 报错的话,需要安装几个包 yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
4.make 编译
5 make install 安装 (注意,安装和编译的命令是在安装的路径下,它会默认安装和编译到第三步--prefix指定的目录下)
二.启动和停止
1.进入到nginx安装的路径(--prefix指定的目录)
2.进入到sbin目录
3.启动 ./nginx
4.关闭 ./nginx -s stop
5.修改配置后重新加载 、或重启(nginx没有关闭) ./nginx -s reload
2.https 模块安装
1 需要安装https模块 ,执行 命令 ./configure --prefix=/home/software/nginx/nginxlocation --with-http_stub_status_module --with-http_ssl_module
2. 执行编译命令 make
3. 执行安装命令 make install
4. 去安装路径sbin下启动 ./nginx
3.负载均衡/反向代理
1.配置upstream 即可
upstream myProxy {
ip_hash;
server 127.0.0.1:8080;
server 127.0.0.1:80;
}
server {
listen 80;
server_name jinjian.*;
access_log logs/host.access.log main;
location / {
proxy_pass http://myProxy;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8080;
server_name jinjian.*;
access_log logs/host.access.log main;
location / {
proxy_pass http://myProxy;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#https配置
server {
listen 443 ssl;
server_name localhost;
#开启 如果把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
#ssl on;
ssl_certificate /home/software/nginx/httpscert/Nginx/1_jinjian.xyz_bundle.crt;
ssl_certificate_key /home/software/nginx/httpscert/Nginx/2_jinjian.xyz.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
}
80端口 https访问其他路径
server {
listen 80;
rewrite ^/(.*) https://$server_name$request_uri?permanent;
}
server {
listen 443 ssl;
server_name jinjian.xyz;
#开启 如果把ssl on;这行去掉,ssl写在443端口后面。这样http和https的链接都可以用
ssl on;
ssl_certificate /home/software/nginx/httpscert/Nginx/1_jinjian.xyz_bundle.crt;
ssl_certificate_key /home/software/nginx/httpscert/Nginx/2_jinjian.xyz.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;
}
location /api {
proxy_pass https://myProxy;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
esay!!