安装Nginx

http://nginx.org/en/download.html 找到对应版本
下载Nginx源码 wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@jrpt-2 software]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
[root@jrpt-2 software]# tar -zxvf nginx-1.12.2.tar.gz
[root@jrpt-2 software]# cd nginx-1.12.2
./configure nginx运行依赖软件是否缺少
[root@jrpt-2 nginx-1.12.2]# ./configure —prefix=/usr/local/nginx
提示 ./configure: error: the HTTP rewrite module requires the PCRE library. 安装依赖
[root@jrpt-2 nginx-1.12.2]# yum install -y pcre pcre-devel zlib zlib-devel
编译源码与安装
[root@jrpt-2 nginx-1.12.2]# make & make install

Nginx 配置为系统服务

[root@jrpt-2 system]# cd /lib/systemd/system
[root@jrpt-2 system]# vim nginx.service
输入已下内容
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
重新载入systemctl配置
[root@jrpt-2 system]# systemctl daemon-reload
[root@jrpt-2 system]# systemctl start nginx
Nginx 默认配置文件为/usr/local/nginx/conf/nginx.conf
nginx.conf 配置参考
user root root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;}
http {
include mime.types;
default_type application/octet-stream;
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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#金融平台门户入口
server {
listen 9090;
server_name 127.0.0.1;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:3000/;
}
location /finance-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
error_page 500 502 503 504 404 /50x.html;
location = /50x.html {
root html;
}
}
#金融平台运营后台入口
server {
listen 9091;
server_name 127.0.0.1;
location / {
root /home/dev/project/finance-opt-front;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /lottery-annual {
alias /home/dev/project/lottery-annual;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /finance-opt-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8081/;
}
error_page 500 502 503 504 404 /50x.html;
location = /50x.html {
root html;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.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;
# }
#}
}