下载安装
- centos7下RPM方式安转nginx
1.下载对应当前系统版本的nginx包(package)
# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2建立nginx的yum仓库
# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
3 下载并安装nginx
# yum install nginx
4 启动nginx服务
systemctl start nginx
设置图片服务器
- 查找安装路径
ps aux | grep nginx
// 结果
root 12563 0.0 0.2 46496 2156 ? Ss 18:05 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
- 编辑配置文件
总配置地址:
/etc/nginx/nginx.conf
服务器地址:
/etc/nginx/conf.d/default.conf
此文件里设置图片访问地址:
#-----------------img -----------------------
location ~ .*\.(gif|jpg|jpeg|png)$ {
expires 24h;
root /usr/nginx/images/;#指定图片存放路径
access_log /usr/nginx/images.log;#日志存放路径
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
proxy_temp_path /usr/nginx/images;#图片访问路径
proxy_redirect off;
proxy_set_header Host 127.0.0.1;
client_max_body_size 10m;
client_body_buffer_size 1280k;
proxy_connect_timeout 900;
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 40k;
proxy_buffers 40 320k;
proxy_busy_buffers_size 640k;
proxy_temp_file_write_size 640k;
if ( !-e $request_filename)
{
proxy_pass http://127.0.0.1;#默认80端口
}
}
- 修改了nginx.conf配置,则需要重启才生效
// 命令
/usr/sbin/nginx -s reload
结果
如果报错
nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
下面命令解决
/usr/sbin/nginx -c /etc/nginx/nginx.conf