Linux下nginx的安装

Nginx安装

下载地址,找自己想要的版本,下面版本号对应修改即可
在这里插入图片描述

#解压文件
tar -zxvf nginx-1.16.1.tar.gz
#把解压的出来的移动到/usr/local/nginx中
mv nginx-1.16.1 /usr/local/nginx
#进入对应路径
cd /usr/local/nginx
#执行配置
./configure
#可能提示错误“checking for C compiler ... not found”,是缺少对应环境,执行
yum -y install gcc
yum -y install gcc-c++
#再次执行配置
./configure
#执行配置./configure如果最后错误提示
#./configure: error: the HTTP rewrite module requires the PCRE library.
#You can either disable the module by using --without-http_rewrite_module
#option, or install the PCRE library into the system, or build the PCRE library
#statically from the source with nginx by using --with-pcre=<path> option.
#上述错误证明你的环境当中缺少pcre包
#安装 pcre
yum -y install pcre-devel openssl openssl-devel
#环境安装完成之后
# 执行配置
./configure
# 编译安装(默认安装在/usr/local/nginx)
make && make install
#Nginx验证
启动nginx:/usr/local/nginx/sbin/nginx
页面访问自己服务器ip地址,比如:http://192.168.88.128/

nginx.conf配置文件

user root root;
worker_processes auto;

error_log /data/wwwlogs/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
	  use epoll;
	  worker_connections 51200;
	  multi_accept on;
}

http {
	  include mime.types;
	  default_type application/octet-stream;
	  server_names_hash_bucket_size 128;
	  client_header_buffer_size 32k;
	  large_client_header_buffers 4 32k;
	  client_max_body_size 1024m;
	  client_body_buffer_size 10m;
	  sendfile on;
	  tcp_nopush on;
	  keepalive_timeout 120;
	  server_tokens off;
	  tcp_nodelay on;
	
	  fastcgi_connect_timeout 300;
	  fastcgi_send_timeout 300;
	  fastcgi_read_timeout 300;
	  fastcgi_buffer_size 64k;
	  fastcgi_buffers 4 64k;
	  fastcgi_busy_buffers_size 128k;
	  fastcgi_temp_file_write_size 128k;
	  fastcgi_intercept_errors on;
	
	  #Gzip Compression
	  gzip on;
	  gzip_buffers 16 8k;
	  gzip_comp_level 6;
	  gzip_http_version 1.1;
	  gzip_min_length 256;
	  gzip_proxied any;
	  gzip_vary on;
	  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

	    # 配置具体的转发行为
	    upstream tomcat {
	        server 127.0.0.1:8766 fail_timeout=0;
	    }

    #具体配置看实际需求
    server {
        listen 8848;

        server_name localhost;

        gzip on;
        gzip_min_length 100;
        gzip_types text/plain text/css application/xml application/javascript;
        gzip_vary on;
        
        location / {
            root   /developer/project;
            index  index.html index.htm;
            try_files $uri $uri/ /index.html;
        }
		
        location /test-boot/ {
                proxy_set_header Host $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:8484/;
        }
    }
}

如果配置完成了还是不能代理访问,可以尝试用命令关闭防火墙:systemctl stop firewalld,关闭之后可以访问就是端口没开,或者云服务安全组中把对应端口开放

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值