centos7下安装、配置Nginx、设置Nginx开机自启动
测试环境:
[root@centos-linux ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@centos-linux ~]# php --version
PHP 7.2.32 (cli)
首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)
1、安装相关的依赖包。
yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2、下载Nginx
wget http://nginx.org/download/nginx-1.18.0.tar.gz
3、解压安装包
tar zxvf nginx-1.18.0.tar.gz
4、进入安装包目录
cd nginx-1.18.0/
5、编译安装
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
6、创建 Nginx 运行使用的用户 www:
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
7、nginx.conf最小配置(/usr/local/nginx/conf/nginx.conf),红色为新增内容
user www www;
worker_processes 1;
error_log /usr/local/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/nginx/nginx.pid;
events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;#站点目录
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
8、检查配置文件正确性的命令
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
9、启动Nginx
/usr/local/nginx/sbin/nginx

10、站点访问

11、Nginx常用命令
/usr/local/webserver/nginx/sbin/nginx -s reload # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen # 重启Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop # 停止 Nginx
12、Nginx调用PHP
先启动php-fpm
systemctl start php-fpm // 需要加入systemctl服务后才可以
在配置文件中增加如下内容
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# include fastcgi.conf; #或用此句替代以上两句。不通版本的nginx不一定都包含该文件,如果没有该配置文件,则使用上面两句话。
}
13、使用yum安装Nignx
// yum -y install epel-release // 如果需要添加CentOS EPEL仓库
yum -y install nginx
启动Nginx
systemctl start nginx
14、卸载Nginx
查找nginx相关文件
find / -name nginx*
从源头删除
rm -rf /usr/sbin/nginx
rm -rf /etc/nginx
rm -rf /etc/init.d/nginx
在使用yum清理
yum remove nginx
15、设置Nginx开机自启动
在/lib/systemd/system目录下,创建nginx.service文件
编辑nginx.service文件,增加如下内容
[Unit]
Description=nginx service
After=network.target [Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true [Install]
WantedBy=multi-user.target
# systemctl start nginx.service // 启动nginx服务
# systemctl stop nginx.service // 停止服务
# systemctl restart nginx.service // 重新启动服务
# systemctl list-units --type=service // 查看所有已启动的服务
# systemctl status nginx.service // 查看服务当前状态
# systemctl enable nginx.service // 设置开机自启动
# systemctl disable nginx.service //停止开机自启动
可能遇到的错误提示:
centos7下安装、配置Nginx、设置Nginx开机自启动的更多相关文章
- Centos7下安装配置Redsocks
Redsocks是一个开源的网络程序,代码依赖开源的libevent网络库.Redsocks允许你将所有TCP连接重定向到SOCKS或HTTPS代理,比如Shadowsocks(Centos7下安装配 ...
- Centos7系统下编写systemd脚本设置redis开机自启动
今天想设置redis开机自启动,我觉得这样子比较好,但是在网上找了很长时间发现大家都是基于chkconfig的写法来设置的,并不能由systemd进程来统一管理,所以这里我自己编写了一个,希望大家可以 ...
- CentOS7下安装配置Nginx
一:安装依赖项 1.pcre:2.openssl:3.zlib:4.gcc:可直接通过yum安装 二:创建nginx账户(可以配置nginx.conf的user为此账户) useradd nginx ...
- Centos下安装配置WordPress与nginx教程
感谢大佬:https://www.howtoing.com/how-to-install-wordpress-with-nginx-on-centos-6-2 WordPress是一个免费和开源网站和 ...
- CentOS7下安装配置vncserver
之前试了xmanager,不过好像和在centos6有很大不同,居然没成功,然后找到了vncserver,试了下,成了 参考:http://blog.csdn.net/jiangliqing1234/ ...
- Centos7 下安装配置tomcat7
首先下载压缩包 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.78/bin/apache-tomcat-7. ...
- Centos7下安装配置keepalived
这里用的是两台设备做高可用 master服务器ip地址:192.168.12.78 slave服务器ip地址:192.168.12.79 虚拟ip(VIP,一个尚未占用的内网ip即可)地址:192.1 ...
- Linux(centos7)安装redis并设置redis开机自启动
1.下载redis安装包 wget http://download.redis.io/releases/redis-4.0.6.tar.gz 2.解压安装包 tar -zxvf redis-4.0.6 ...
- centos7下安装配置prometheus
prometheus官网:https://prometheus.io/download/ 搭建环境参考:https://blog.csdn.net/baidu_36943075/article/det ...
- Ubuntu14.04下安装redis-3.2.0以及开机自启动
去官网下载Redis-3.2.0.tar.gz,将redis-3.2.0.tar.gz放入/opt目录下 解压redis-3.2.0.tar.gz xiaoyao@xiaoyao-virtual-ma ...
随机推荐
- python_request 接口测试线性框架,模块化思想,增加日志打印
一.大框架 如下为一个简单的线性框架,同时编写common_api 模块,把一个个接口进行封装,案例编写时候只需要直接调用输入参数即可. 二. test_cases 模块具体写法 2.1 commo ...
- BIO/NIO/ANO笔记
一: netty服务器启动过程 serverBootstrap.bind(hostname, port)---> doBind(localAddress);--> 1.1: initAnd ...
- ES6中的字符串
字符串在编程语言中,一直是使用率很高的数据,虽说函数在js语言中是一等公民,但是字符串,怎么也能算得上是千年老二,下面我就一起和大家探讨一下在es6中的一些新用法和特性,特别是在字符串拼接的时候,会解 ...
- 学习响应式编程 Reactor (2) - 初识 reactor
Reactor Reactor 是用于 Java 的异步非阻塞响应式编程框架,同时具备背压控制的能力.它与 Java 8 函数式 Api 直接集成,比如 分为CompletableFuture.Str ...
- RobotFramework + Python 自动化入门 一 (从这里开始)
一.环境搭建 1. 安装Python Python3会自动配置path,安装pip工具(python包安装和管理工具) 2. 安装robotframework library cmd窗口安装命令: p ...
- Typescript学习总结
typescript(以下简称TS)出来也有好长时间了,下面记录一下学习心得. 首先学这门语言前,请确保有以下基础知识: 扎实的javascript基础知识 es6的基础知识 面向对象编程的概念(没有 ...
- dev下拉框选择不同值显示不同控件
单列的ASPxFormLayout直接前台控制就可以了,多列的前台控制后会出现空白 <dx:LayoutItem Caption="内容类型" Height="40 ...
- CCF CSP认证考试在线评测系统
关于 CCF CSP 认证考试在线评测系统 CCF CSP 认证考试简介 CCF 是中国计算机学会的简称.CCF 计算机软件能力认证(简称 CCF CSP 认证考试)是 CCF 于 2014 年推出, ...
- nginx服务跳转
1.什么是页面跳转 将URL信息做改变 将URI信息做改变 完成伪静态配置 2.实现页面跳转的方法 http://nginx.org/en/docs/http/ngx_http_rewrite_mod ...
- Ansible自动化运维应用实战
实验环境 centos7.4 主机名称 IP 配置 用途 controlnode 172.16.1.120 1核/1G/60G ansible slavenode1 172.16.1.121 1核/1 ...