Centos 7.3 x64安装nginx 与反向代理的应用

Centos 7.3 x64安装nginx-1.13.1

nginx-1.13.1 发布日期2017-05-30

测试完成日期:2017.6.22 by evan.li

一、安装必要所需环境:

# yum install autoconf automake gcc gcc-c++ libtool make pkgconfig zlib-devel 

# yum install pcre pcre-devel php-devel httpd-devel

# yum install zlib zlib-devel  

# yum install openssl openssl-devel  

#  groupadd nginx

#  useradd -g nginx nginx

#  mkdir /software

#  cd /software

# wget http://nginx.org/download/nginx-1.13.1.tar.gz

# tar xzf nginx-1.13.1.tar.gz

# cd nginx-1.13.1

安装相关依赖包

[[email protected] nginx-1.13.1]#  yum install libxml2-devel libxslt-devel gd-devel

[[email protected] nginx-1.13.1]#  yum install perl perl-devel perl-ExtUtils-Embed  libatomic_ops-devel

[[email protected] nginx-1.13.1]# ./configure --user=nginx --group=nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --with-select_module --with-poll_module --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cpp_test_module  --with-cpu-opt=CPU --with-pcre  --with-pcre-jit  --with-zlib-asm=CPU --with-libatomic --with-debug --with-ld-opt="-Wl,-E" --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi

[[email protected] nginx-1.13.1]#

....成功结果如下

checking for atomic_ops library ... found

creating objs/Makefile

Configuration summary

+ using system PCRE library

+ using system OpenSSL library

+ using system zlib library

+ using system libatomic_ops library

nginx path prefix: "/usr/local/nginx"

nginx binary file: "/usr/sbin/nginx"

nginx modules path: "/usr/local/nginx/modules"

nginx configuration prefix: "/etc/nginx"

nginx configuration file: "/etc/nginx/nginx.conf"

nginx pid file: "/var/run/nginx.pid"

nginx error log file: "/var/log/nginx/error.log"

nginx http access log file: "/var/log/nginx/access.log"

nginx http client request body temporary files: "/var/tmp/nginx/client/"

nginx http proxy temporary files: "/var/tmp/nginx/proxy/"

nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"

nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi"

nginx http scgi temporary files: "/var/tmp/nginx/scgi"

./configure: warning: the "--with-ipv6" option is deprecated

[[email protected] nginx-1.13.1]# make

[[email protected] nginx-1.13.1]# make install

[[email protected] nginx-1.13.1]# nginx -V

nginx version: nginx/1.13.1

将启动脚本(见附件)上传到/etc/init.d/ 目录下面

# chmod +x /etc/init.d/nginx

# chkconfig --add nginx

# chkconfig nginx on

# chkconfig --list nginx

# mkdir -p /var/tmp/nginx/client

编辑配置文件,红色字体为修改或添加后的项目

# vi /etc/nginx/nginx.conf

user  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       /etc/nginx/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  /var/log/nginx/access.log  main;

sendfile        on;

tcp_nopush      on;

tcp_nodelay     on;

types_hash_max_size 2048;

client_max_body_size 20M;

keepalive_timeout  65;

gzip  on;

gzip_disable "msie6";

gzip_comp_level 6;

gzip_min_length 1100;

gzip_buffers 16 8k;

gzip_proxied any;

gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml;

server {

listen       80;

server_name  110.110.220.54;

charset utf-8;

location / {

root  /var/www/html/dongying;

index  index.html index.htm index.jsp login.jsp;

}

#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;

#    }

#}

# 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;

#    }

#}

}

检测配置文件是否有语法错误

[[email protected] tmp]# nginx -t -c  /etc/nginx/nginx.conf

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

加入防火墙允许

[[email protected] nginx]# firewall-cmd --add-service=http --permanent

[[email protected] nginx]# firewall-cmd --reload

[[email protected] nginx]# systemctl restart firewalld

启动nginx服务

[[email protected] nginx]# service nginx start


再用户就可以使用IP 110.110.220.54直接访问网站了。

-----------------------------------------------------------------------------------

反向代理的应用

公司同事,用tomcat发布了2个项目,可以用IP访问他的项目

A项目地址  http://110.110.220.54:8080/dy/jsp/index.jsp

B项目地址  http://110.110.220.54:8080/dy/position/login.jsp

现在使用nginx,用公司域名www.dongying.com来发布他的项目,方法如下:

绿色部分为项目A,设定正常后用www.dongying.com来访问。

橙色部分为项目B,设定正常后用www.dongying.com:8080/dy/position/login.jsp来访问。

server {

listen 80;

server_name www.dongying.com;

charset utf-8;

location / {

proxy_pass http://www.dongying.com:8080/dgmy/jsp/;

index index.html index.htm index.jsp login.jsp;

}

location ~ \.(gif|jpg|jpeg|png|bmp|swf|css|js)$

{

access_log off;

expires 1d;

root /opt/tomcat/webapps/dy/;

break;

}

location /dy/position/ {

proxy_pass http://www.dongying.com:8080/dy/position/login.jsp;

proxy_set_header           Host $host;

proxy_set_header  X-Real-IP  $remote_addr;

proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size  100m;

root   html;

index  index.html index.htm index.jsp login.jsp;

}

测试完成日期:2017.6.23 by evan.li

时间: 2024-08-08 08:36:02

Centos 7.3 x64安装nginx 与反向代理的应用的相关文章

CentOS 7 安装 Nginx 配置反向代理

Linux使用Nginx Yum存储库上安装Nginx,适用于Red Hat Enterprise Linux和CentOS系统. 1.添加设置Nginx Yum存储库 在CentOS中首次安装Nginx时,需要添加Nginx软件包,使用以下命名,添加安装 sudo yum install yum-utils 设置Yum存储库,请创建/etc/yum.repos.d/nginx.repo配置文件,配置内容如下 [nginx-stable] name=nginx stable repo baseu

CentOS 7 安装Nginx做反向代理

题记 须要使用nginx的反向代理功能,測试环境为centos+NGINX 1.8.0. 跳过一些繁琐的问题,直接记录核心 步骤 (1)centos 安装在VM中.因此须要注意网络连接问题 (2)安装nginx使用的是具有网络的yum功能 (3)配置centos防火墙,须要开启80 port (4)nginx 反向代理配置 (5)性能优化设置(兴许工作...) 实现 一. yum安装nginx 先加入nginx源,測试使用最新的nginx 1.8.0 rpm -ivh http://nginx.

Linux安装Nginx使用反向代理

nginx的反向代理功能(自带了反向代理的功能,天生的二道贩子)1.实验环境准备准备2个服务器,都安装好nginx软件nginx1 192.168.13.79 作为web服务器 (理解为火车票售票点)nginx2 192.168.13.24 作为反向代理服务器(黄牛)    用户通过浏览器去访问   黄牛 (代理)浏览器访问192.168.13.24 > 192.168.13.79 2.在反向代理服务器中添加配置nginx负载均衡集群的概念:一堆服务器做一件事 原文地址:https://www.

Linux ( Centos 7.3 x64) 安装 nginx (一)

安装环境所需插件 1. 安装gcc   GCC(GNU Compiler Collection,GNU编译器套件)是由GNU开发的编程语言译器.GNU编译器套件包括C.C++. Objective-C. Fortran.Java.Ada和Go语言前端,也包括了这些语言的库(如libstdc++,libgcj等.) gcc -v yum install -y gcc 2.安装 PCRE  PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 pe

linux 安装 nginx 及反向代理配置

Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,以下为Linux centos平台下安装nginx并配置反向代理的过程(采用源码安装的方式) 一:安装编译环境gcc g++ 和make(用于编译源代码成可执行文件) 1yum install gcc gcc-c++ 2 yum -y install gcc automake autoconf libtool make 二:安装pcre (nginx rewrite依赖pcre库)zlib(用于gzip压缩)

编译安装nginx实现反向代理、负载均衡、缓存功能

一.编译安装nginx 1.下载 [[email protected] ~]# wget http://nginx.org/download/nginx-1.10.0.tar.gz 2.解压 [[email protected] ~]# tar xf nginx-1.10.0.tar.gz [[email protected] ~]# cd nginx-1.10.0 3.安装依赖组件 [[email protected] nginx-1.10.0]# yum install pcre-devel

ESA2GJK1DH1K微信小程序篇: 安装Nginx,配置反向代理

前言 一,为什么需要反向代理 小程序访问的是 443端口,咱需要把443端口的数据传给MQTT 这节为了避免大家配置出错,以下源码已经配置. 如果大家想自己配置,请参考 https://www.cnblogs.com/yangfengwu/category/1558450.html 拷贝文件到服务器 一,下面文件已经配置好了反向代理,用户只需要修改域名和SSL文件即可使用 注:如果自己的服务器不需要PHP,可不拷贝php7.zip 解压出来文件 进入以下目录,打开nginx.conf 1.打开n

CentOS 6.5 编译安装Nginx

Nginx Nginx("enginex") 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP代理服务器. Nginx 是由Igor Sysoev为俄罗斯访问量第二的Rambler.ru站点开发的,它已经在该站点运行超过四年多了.Igor 将源代码以类BSD许可证的形式发布.自Nginx 发布四年来,Nginx 已经因为它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名了.目前国内各大门户网站已经部署了Nginx,如新浪.网易.腾讯等:国内

【NodeJs】Linux安装NodeJs并配合Nginx实现反向代理

Linux安装NodeJs并配合Nginx实现反向代理 NodeJs 是什么 Node.js是一个Javascript运行环境(runtime).实际上它是对Google V8引擎进行了封装.V8引 擎执行Javascript的速度非常快,性能非常好. Node.js对一些特殊用例进行了优化,提供了替代的API,使得V8在非浏览器环境下运行得更好. 本地安装(OS X) 版本选择 V4.4.4,长期支持版本,成熟可靠 V6.2.0 稳定版本,最新特性 这里我还是倾向于使用最新的版本~ 下载安装包