nginx在centos7环境下配置webserver

本文介绍如何在CentOS7环境下安装Nginx,并提供了详细的配置步骤及示例,包括webserver的基本配置文件nginx.conf及其附属文件global.conf的内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.nginx在centos7环境安装

打开linux终端输入如下命令,安装nginx
yum update
yum -y install nginx

或者

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum -y install nginx

2.nginx配置web server

配置文件nginx.conf通用配置如下

user root root;
worker_processes 4;
pid /run/nginx.pid;
daemon off;

events {  }

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  gzip on;
  gzip_disable "msie6";
  include ./global.conf;
}

其中,和nginx.conf在同级目录下的global.conf文件配置如下(webserver配置)

server {
        listen          0.0.0.0:80;
        server_name     _;

	location / {
		root            /var/www/html/website;
        	index           index.html index.htm;
	}
        access_log      /var/log/nginx/default_access.log;
        error_log       /var/log/nginx/default_error.log;
}

3.启动nginx

在终端输入如下命令,启动nginx

nginx -c /home/sample/nginx/nginx.conf

启动成功后,访问web路径localhost:80,其中80为global.conf配置的端口


注意:nginx.conf 第一行,用户名改为登录的用户组、用户名

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值