Linux安装nginx

下载压缩包

wget http://nginx.org/download/nginx-1.6.3.tar.gz

解压

tar -zxvf nginx-1.6.3.tar.gz

安装配置(这里默认)

./configure

这里一般会有几个依赖错误:

./configure: error: the HTTP gzip module requires the zlib library
yum install zlib-devel


./configure: error: C compiler cc is not found
yum  -y install gcc

./configure: error: the HTTP rewrite module requires the PCRE library
yum install pcre-devel

再次执行

./configure

出现如下就ok了

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using builtin md5 code
  + sha1 library is not found
  + using system zlib library

可以看到OpenSSL和sha1未找到,这里可以不用管,但如果想用其功能可以安装对应的依赖

yum install openssl openssl-devel

yum install perl-Digest-SHA1.x86_64

./configure --with-http_stub_status_module --with-http_ssl_module


编译 安装

make && make install


默认目录 

cd /usr/local/nginx/


可以加到环境变量中:

vim /etc/profile
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
source /etc/profile

测试下

nginx -v

配置文件 默认路径(/usr/local/nginx/conf/)

#Nginx所用用户和组,window下不指定
#user  niumd niumd;

#工作的子进程数量(通常等于CPU数量或者2倍于CPU)
worker_processes  2;

#错误日志存放路径
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

#指定pid存放文件
pid        logs/nginx.pid;

events {
    #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。
    #use epoll;
    
    #允许最大连接数
    worker_connections  2048;
}

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  off;
    access_log  logs/access.log;

    client_header_timeout  3m;
    client_body_timeout    3m;
    send_timeout           3m;
 
    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;

    #keepalive_timeout  75 20;
    proxy_next_upstream  off;
    #include    gzip.conf;
    upstream localhost {
      #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能,需要通过缓存进行共享解决。
      #同一机器在多网情况下,路由切换,ip可能不同
      ip_hash; 
      server localhost:8090;
     }

    server {
            listen       8080;
            server_name  127.0.0.1; #这里设置域名或者请求ip
            location / {
            		proxy_connect_timeout   30;
            		proxy_send_timeout      30;
            		proxy_read_timeout      30;
                    proxy_pass http://localhost;
            }
            #静态文件访问
	    location ~ ^/(upload|static)/ {
             root /data/www;  
             expires 2d;
            }
            
   }
}

检查配置文件是否正确

nginx -t


启动

nginx

重启

nginx -s reload

关闭可以直接kill掉进程

ps -ef | grep nginx

kill -9 nginx



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux安装Nginx有几种方法。一种方法是通过包管理器进行安装。您可以使用命令"yum install nginx"来安装最新的稳定版本,默认情况下安装的是Nginx 1.20.2版本。另外一种方法是通过源码编译安装Nginx。这需要下载Nginx安装包并解压缩,然后进行依赖安装和配置。具体步骤如下: 1. 下载Nginx安装包,并解压缩。 2. 安装Nginx的依赖包。 3. 进入解压缩后的Nginx目录,执行"./configure"命令进行配置。 4. 执行"make"命令进行编译。 5. 执行"make install"命令进行安装。 6. 修改Nginx的配置文件"nginx.conf",可以设置用户和用户组等参数。 7. 启动Nginx,可以使用命令"nginx"。 8. 停止或重启Nginx,可以使用命令"nginx -s stop"和"nginx -s reload"。 9. 设置Nginx开机自启动,可以将Nginx添加到系统的启动项中。 10. 配置防火墙,确保80端口开放以允许Nginx的HTTP访问。 根据您的需求和喜好,您可以选择适合您的安装方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux安装nginx详细步骤](https://blog.csdn.net/adaizzz/article/details/126669430)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [linux 系统下四种nginx安装方法](https://blog.csdn.net/shallow72/article/details/123878716)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值