Nginx安装配置
2017-10-23 15:26
218 查看
Nginx安装配置
一、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtoolopenssl openssl-devel
二、首先要安装 PCRE
该文件为正则表达式库。让Nginx支持rewrite需要安装这个库。1、下载 PCRE安装包
下载地址: https://sourceforge.net/projects/pcre/files/pcre/
[root@zfr src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz
2、解压安装包:
[root@zfr src]# tar -zxvf pcre-8.41.tar.gz3、进入安装包目录
[root@zfr src]# cd pcre-8.414、编译安装
[root@bzfr pcre-8.41]# ./configure[root@zfr pcre-8.41]# make && make
install
5、查看pcre版本
[root@zfr pcre-8.41]# pcre-config--version安装 Nginx
1、下载 Nginx可以选择自己需要的版本
下载地址:http://nginx.org/en/download.html
[root@zfr src]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
2、解压安装包
[root@zfr src]# tar -zxvf nginx-1.10.3.tar.gz3、进入安装包目录
[root@zfr src]# cd nginx-1.10.34、编译安装
[root@zfr nginx-1.10.3]# ./configure--prefix=/home/nginx--with-http_stub_status_module--with-http_ssl_module--with-pcre=/usr/local/src/pcre-8.41[root@zfr nginx-1.10.3]# make
[root@zfr nginx-1.10.3]# make
install
5、查看nginx版本
[root@zfr nginx-1.10.3]# /home/nginx/sbin/nginx-vNginx 配置
配置nginx.conf
[root@zfr conf]# cat/nginx/conf/nginx.conf#user nobody; #工作用户
worker_processes 4; #工作线程数,建议和CPU内核数一样
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #错误日志级别
#pid logs/nginx.pid; #pid的存放路径
events {
worker_connections 10240; #同时接收的网络连接数
}
http {
include mime.types; #其中定义了一个types结构,包含了浏览器能够识别的MIME类型以及对应相关类型的文件的后缀名。
default_type application/octet-stream; #默认值为text/plain 为types模块定义的application/octet-stream
log_format main '$remote_addr - $remote_user [$time_local] "$request" $hostname $server_name '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for $upstream_cache_status '
'"$upstream_http_content_type" $request_time $upstream_response_time $bytes_sent $request_length '
'"$upstream_addr"';
#access_log logs/accesstest.log main;
access_log /home/ycm/nginxbin/logs/host.access.log main;
sendfile on; #使用sendfile()传输文件
#sendfile_max_chunk size; #size大于0,每个work process每次调用传输的数据量不能超过这个。默认为0无限制。
#tcp_nopush on;
client_max_body_size 50M;
keepalive_timeout 65; #连接超时时间,默认为75s。
#gzip on;
upstream receiver{
server 10.3.5.XX:6101;
}
upstream heartbeat{
server 10.3.5.XX:6201;
}
upstream query{
server 10.3.5.XX:6107;
}
upstream webapp{
server 10.3.5.XX:8080;
}
upstream gf{
server 10.3.5.XX:3000;
}
upstream realtime{
server 10.3.5.XX:6108;
}
upstream graphquery{
server 10.3.5.XX:6202;
}
upstream manager{
server 10.3.5.XX:6109;
}
upstream openapi{
server 10.3.5.XX:8106;
server 10.3.5.XX:8106;
}
upstream cloudsync{
server 10.3.5.XX:6809;
}
upstream weixin{
server 10.3.5.XX:6105;
}
server {
listen 80;
server_name XX.XX.XX.XX ;
#charset koi8-r;
#access_log /home/ycm/nginxbin/logs/host.access.log combined gzip flush=5m ;
access_log /home/ycm/nginxbin/logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://webapp;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #一般的web服务器用这个 X-Real-IP 来获取源IP
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; #如果nginx 服务器是作为反向代理服务器的,则这个配置项是必须的;否则看不到源IP
rewrite ^/$ /ycm-appmonitor/ redirect;
}
location /heartbeat {
root html;
index index.html index.htm;
proxy_pass http://heartbeat;
rewrite ^/$ /ycm-appmonitor/ redirect;
}
location /send {
root html;
index index.html index.htm;
proxy_pass http://openapi;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #一般的web服务器用这个 X-Real-IP 来获取源IP
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; #如果nginx 服务器是作为反向代理服务器的,则这个配置项是必须的;否则看不到源IP
rewrite ^/$ /ycm-appmonitor/ redirect;
}
#云同步的接口url错误,这个url直接成功
location /send/api/visit {
return 200 '{"result":"ok","nginx":"true"}';
}
location /api {
root html;
index index.html index.htm;
proxy_pass http://openapi;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; #一般的web服务器用这个 X-Real-IP 来获取源IP
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; #如果nginx 服务器是作为反向代理服务器的,则这个配置项是必须的;否则看不到源IP
}
location /graphquery {
root html;
index index.html index.htm;
proxy_pass http://graphquery;
rewrite ^/$ /ycm-appmonitor/ redirect;
}
location /render {
root html;
index index.html index.htm;
proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_set_header Cache-Control "max-age=3600";
add_header Access-Control-Allow-Origin *;
proxy_pass http://gf;
}
location /realtime {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin *;
proxy_pass http://realtime;
}
location /manager{
root html;
index index.html index.htm;
proxy_pass http://manager;
}
location /sync{
root html;
index index.html index.htm;
proxy_pass http://cloudsync;
}
location /dashboard-solo {
root html;
index index.html index.htm;
proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_set_header Cache-Control "max-age=3600";
add_header Access-Control-Allow-Origin *;
proxy_pass http://gf;
}
location /dashboard {
root html;
index index.html index.htm;
proxy_pass http://gf;
proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_set_header Cache-Control "max-age=3600";
add_header Access-Control-Allow-Origin *;
}
location /api/datasources {
root html;
index index.html index.htm;
proxy_pass http://gf;
proxy_set_header Authorization "Bearer eyJrIjoidnhXVnVjTkVWVW5McEx1NDhDWTd4aVZyWGdRb3BDTnIiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_set_header Cache-Control "max-age=3600";
add_header Access-Control-Allow-Origin *;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# 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;
# }
#}
server {
listen 6060;
server_name 10.3.5.40;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log /home/ycm/nginxbin/logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
#proxy_set_header Authorization "Bearer eyJrIjoiSGlpd2V3aGlFWlFONDdham9EUHQzNjdxUVBWbE1vWlMiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_pass http://receiver;
}
}
server {
listen 6061;
server_name 10.3.5.40;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log /home/ycm/nginxbin/logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
#proxy_set_header Authorization "Bearer eyJrIjoiSGlpd2V3aGlFWlFONDdham9EUHQzNjdxUVBWbE1vWlMiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_pass http://heartbeat;
}
}
server {
listen 6062;
server_name 10.3.5.40;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log /home/ycm/nginxbin/logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
#proxy_set_header Authorization "Bearer eyJrIjoiSGlpd2V3aGlFWlFONDdham9EUHQzNjdxUVBWbE1vWlMiLCJuIjoid2FuZ2hiayIsImlkIjoxfQ==";
proxy_pass http://query;
}
}
server {
listen 6105;
server_name 10.3.5.40;
#charset koi8-r;
#access_log logs/host.access.log main;
access_log /home/ycm/nginxbin/logs/host.access.log main;
location /msg/weixin/access {
#root html;
#index index.html index.htm;
proxy_pass http://weixin;
}
}
#HTTPS server
server {
listen 443 ssl;
server_name 60.205.85.147 yyy.yonyoucloud.com 10.3.5.40 yyy.yonyou.com 60.205.84.199;
access_log /home/ycm/nginxbin/logs/host.access.log main;
ssl_certificate /home/ycm/nginxbin/crt/_.yonyou.com_bundle.crt;
ssl_certificate_key /home/ycm/nginxbin/crt/_.yonyou.com.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;
proxy_pass http://webapp;
rewrite ^/$ /ycm-appmonitor/ redirect;
}
}
}
检查配置文件ngnix.conf
[root@zfr conf]# /home/nginx/sbin/nginx-t相关文章推荐
- nginx安装配置
- nginx的安装与配置
- Nginx的安装配置和自定义模块添加 Nginx第一篇
- 【安装第三方yum源】nginx php-fpm安装配置
- Linux下安装php环境并且配置Nginx支持php-fpm模块[www]
- Nginx安装配置与HelloWorld
- nginx初级安装配置
- zabbix安装-----nginx安装和配置
- ubunut 安装nginx基本目录结构介绍和配置使用方法
- Nginx源码安装及调优配置
- nginx安装路径,查找配置文件以及如何配置
- nginx安装及配置
- Ansible 一键配置安装Keepalived+Nginx作为前端,httpd+php作为后端
- ubuntu中安装nginx并配置SSL
- Nginx的安装配置
- Linux(Red Hat Enterprise)下安装nginx与sticky模块,并配置开机自启动图文教程
- VPS配置安装nginx和vsftpd方法详解
- Linux(CentOS)下,下载安装Nginx并配置
- nginx_concat_module 安装和配置
- Centos下Nginx+PHP+MySql的安装和配置(综合整理)