nginxyum安装配置
时间: 2023-12-05 10:41:29 浏览: 182
以下是在CentOS 7上使用yum安装nginx并进行简单配置的步骤:
1.使用root用户登录服务器并更新yum源:
```shell
sudo yum update
```
2.安装nginx:
```shell
sudo yum install nginx
```
3.启动nginx服务:
```shell
sudo systemctl start nginx
```
4.验证nginx是否成功安装:
```shell
nginx -v
```
5.配置nginx:
nginx的配置文件位于/etc/nginx/nginx.conf。可以使用vim或nano编辑器打开该文件进行编辑。以下是一个简单的nginx配置示例:
```shell
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;
}
}
}
```
6.重新加载nginx配置:
```shell
sudo nginx -s reload
```
阅读全文