Nginx配置及遇到的问题
1.添加资源库
在 CentOS 系统上安装 Nginx ,你得先去添加一个资源库:
1 vim /etc/yum.repos.d/nginx.repo
输入下面几行代码:
1 [nginx] 2 name=nginx repo 3 baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 4 gpgcheck=0 5 enabled=1
2.yum 命令去安装 nginx
1 yum install nginx
3.测试nginx配置文件
当你执行 nginx -t 的时候,nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径:
1 [root@localhost ~]# nginx -t
打印结果:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
4.Nginx常用命令
systemctl stop nginx.service #停止Nginx服务
systemctl start nginx.service #开启Nginx服务
systemctl restart nginx.service #重启Nginx服务
systemctl status nginx.service #检查Nginx服务状态
systemctl enable nginx.service #设置开机自启动
systemctl disable nginx.service #取消开机自启动
5.测试访问
在浏览器输入 ip:port 进行访问

我的是监听在80端,端口省略不写,需要注意的是:我 Linux 80端口是不开放的,所以需要开放80端口,当然也可以关闭防火墙
1 firewall-cmd –state ----> 查看防火墙状态 2 service firewalld start ----> 启动防火墙 3 service firewalld restart ----> 重启防火墙 4 service firewalld stop -----> 关闭防火墙 5 firewall-cmd --query-port=80/tcp ----->查询端口是否开放 6 firewall-cmd --permanent --add-port=80/tcp ----->开放80端口 7 firewall-cmd --permanent --remove-port=80/tcp ----->移除端口 8 firewall-cmd --reload ----->重启防火墙(修改配置后要重启防火墙)
5.配置ftp服务器访问路径:
需要 cd /etc/nginx/ 进入nginx目录,使用 vi 编辑器修改配置文件 default.conf:
[root@localhost nginx]# vi conf.d/default.conf
我的 default.conf 配置文件的内容,原来的配置文件没改变,只是添加了如下的内容:
location ~ .*\.(gif|jpg|jpeg|png)$ { expires 24h; root /var/public_root/;#指定图片存放路径 access_log /var/log/nginx/access.log;#图片 日志路径 proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /var/public_root/;#代理临时路径 proxy_redirect off; proxy_set_header Host 127.0.0.1; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 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:8088;#代理访问地址 } }
标绿的是我ftp服务器的位置,需要注意
测试 Nginx + ftp t图片服务器的搭建:

OK ! 到此。说明搭建成功了
重启Nginx遇到的Failed to read PID from fil 错误
解决方法:
1 mkdir -p /etc/systemd/system/nginx.service.d 2 printf "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf 3 systemctl daemon-reload 4 systemctl restart nginx.service
博主也是菜鸟一只,刚刚踏入Linux的学习,记录一下自己的学习历程,若给您带来帮助,不胜荣幸;若有什么问题,欢迎踩我,大家共同学习进步,提高技术,谢谢!

浙公网安备 33010602011771号