热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Centos7.3x64安装nginx与反向代理的应用

Centos7.3x64安装nginx-1.13.1nginx-1.13.1发布日期2017-05-30测试完成日期:2017.6.22byevan.li一、安装必要所需环境:#

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  


安装相关依赖包

[root@ns1 nginx-1.13.1]#  yum install libxml2-devel libxslt-devel gd-devel

[root@ns1 nginx-1.13.1]#  yum install perl perl-devel perl-ExtUtils-Embed  libatomic_ops-devel



[root@ns1 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


[root@ns1 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


[root@ns1 nginx-1.13.1]# make

[root@ns1 nginx-1.13.1]# make install


[root@ns1 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;

    #    }

    #}

}



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

[root@host-cn 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


加入防火墙允许

[root@ns1 nginx]# firewall-cmd --add-service=http --permanent 

[root@ns1 nginx]# firewall-cmd --reload

[root@ns1 nginx]# systemctl restart firewalld


启动nginx服务

[root@ns1 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


本文出自 “虚拟化应用” 博客,请务必保留此出处http://liwenhn.blog.51cto.com/854522/1941434


推荐阅读
  • 负载均衡_Nginx反向代理动静分离负载均衡及rewrite隐藏路径详解(Nginx Apache MySQL Redis)–第二部分
    nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • CEPH LIO iSCSI Gateway及其使用参考文档
    本文介绍了CEPH LIO iSCSI Gateway以及使用该网关的参考文档,包括Ceph Block Device、CEPH ISCSI GATEWAY、USING AN ISCSI GATEWAY等。同时提供了多个参考链接,详细介绍了CEPH LIO iSCSI Gateway的配置和使用方法。 ... [详细]
  • 本文介绍了在Mac上安装Xamarin并使用Windows上的VS开发iOS app的方法,包括所需的安装环境和软件,以及使用Xamarin.iOS进行开发的步骤。通过这种方法,即使没有Mac或者安装苹果系统,程序员们也能轻松开发iOS app。 ... [详细]
  • GetWindowLong函数
    今天在看一个代码里头写了GetWindowLong(hwnd,0),我当时就有点费解,靠,上网搜索函数原型说明,死活找不到第 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文整理了315道Python基础题目及答案,帮助读者检验学习成果。文章介绍了学习Python的途径、Python与其他编程语言的对比、解释型和编译型编程语言的简述、Python解释器的种类和特点、位和字节的关系、以及至少5个PEP8规范。对于想要检验自己学习成果的读者,这些题目将是一个不错的选择。请注意,答案在视频中,本文不提供答案。 ... [详细]
  • express工程中的json调用方法
    本文介绍了在express工程中如何调用json数据,包括建立app.js文件、创建数据接口以及获取全部数据和typeid为1的数据的方法。 ... [详细]
  • 大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记
    本文介绍了大数据Hadoop生态(20)MapReduce框架原理OutputFormat的开发笔记,包括outputFormat接口实现类、自定义outputFormat步骤和案例。案例中将包含nty的日志输出到nty.log文件,其他日志输出到other.log文件。同时提供了一些相关网址供参考。 ... [详细]
  • 第四讲ApacheLAMP服务器基本配置Apache的编译安装从Apache的官方网站下载源码包:http:httpd.apache.orgdownload.cgi今 ... [详细]
  • 原文地址http://balau82.wordpress.com/2010/02/28/hello-world-for-bare-metal-arm-using-qemu/最开始时 ... [详细]
author-avatar
choojo深呼吸
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有