centos7安装配置nginx
时间: 2023-10-30 18:07:02 浏览: 70
好的,以下是 centos7 安装配置 nginx 的步骤:
1. 安装 nginx
在终端中输入以下命令:
```
sudo yum install epel-release
sudo yum install nginx
```
2. 启动 nginx
输入以下命令:
```
sudo systemctl start nginx
```
3. 配置 nginx
配置文件位于 `/etc/nginx/nginx.conf`,可以使用编辑器打开进行修改。以下是一个简单的配置示例:
```
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/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;
keepalive_timeout 65;
server {
listen 80;
server_name example.com;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
}
```
4. 重启 nginx
输入以下命令:
```
sudo systemctl restart nginx
```