第一章:环境配置和nginx安装前提备注为了学习python相关内容,笔者在网上购买了一台服务器,经过两天的忙碌工作,终于搭建好了相关环境。所有软件都使用最新版本,所以踩到发现了很多坑,现在把这些步骤写出来给大家提供一个参考,因为是第一次写文章,肯定有不足的地方,还请指教你的建议。环境预览centos7.2nginx1.13.8php7.2.2python2.7.5/3.6.4mysql5.7.18pgsql10.1服务器Centos购买地址:https://www.vultr.com/$2.5一个月到180一年,1CPU,20GBSSD,512M内存,500G月流量足够学习https://www.aliyun.com/chinaglobal/promotion/overseaall2017也可以选择阿里海外版,比这个配置高一点,40G,1G内存,用完优惠优惠券每年约280。准备关闭防火墙:systemctlstopfirewalld.service查看防火墙状态:firewall-cmd--state安装网络工具:yuminstallnet-tools安装网络工具:yuminstallnmap安装gcc工具:yuminstallgccgcc-c++安装pcre库:yuminstallpcrepcre-devel安装zlib库:yuminstallzlibzlib-devel所有用户默认root安装nginxcd/usr/local/src该文件夹作为安装包wgethttp:///nginx.org/download/nginx-1.13.8.tar.gztar-zxvfnginx-1.13.8.tar.gzcdnginx-1.13.8添加nginx用户和用户组(可以省略,不加也能玩)groupaddnginxuseradd-r-gnginxnginx编译nginx./configure--prefix=/usr/local/nginx--sbin-path=/usr/local/nginx/sbin/nginx--conf-path=/usr/local/nginx/nginx.conf--pid-path=/usr/local/nginx/nginx.pid--user=nginx(上一步省略,可以去掉)--group=nginx(上一步省略,可以去掉))--with-http_ssl_module--with-http_flv_module--with-http_mp4_module--with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/var/tmp/nginx/client/--http-proxy-temp-path=/var/tmp/nginx/proxy/--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/--http-scgi-temp-path=/var/tmp/nginx/scgi/如果在编译过程中报错,大概率是缺少插件包。按照提示安装yum,编译完成就没有问题了。执行make&&makeinstall完成安装配置nginx.confcd/usr/local/nginx/mkdirconf.d(backup)vinginx.conf改listen为8080,去掉43-46前的#,添加includeconf.d/*.conf如下图;测试nginx打开nginx/usr/local/nginx/sbin/nginx打开浏览器输入服务器ip地址:8080出现下图,安装成功添加环境变量(可省略)vi/etc/profileexportPATH=$PATH:/usr/local/nginx/sbinsource/etc/profilenginxstartcd/lib/systemd/system/touchnginx.service输入以下代码:#nginxserviceforsystemd(CentOS7.0+)[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx-sreloadExecStop=/usr/local/nginx/sbin/nginx-sstopPrivateTmp=false[Install]WantedBy=multi-user.target保存退出刷新服务配置systemctldaemon-reload尝试启动服务systemctlstopnginx.servicesystemctlstartnginx.servicesystemctlrestartnginx.servicejoinbootstartsystemctlenablenginx.serviceconfigurationcompleted注1:PrivateTmp的值设置为true,服务启动的时候在/var/tmp/nginx/client/目录下会生成一个类似systemd-private-433ef27ba3d46d8aac286aeb1390e1b-nginx.service-RedVyu/的文件夹用来存放nginx的临时文件,但是我测试的时候执行systemctlstartnginx。执行service命令会报如下错误:但执行nginx-t查看配置文件后nginx正常启动。我怀疑问题是由用户权限引起的。false不影响使用注2:注意nginx、/usr/local/nginx/sbin/nginx、systemctlxxxxnginx.service之间的关系,systemctl命令不能操作nginx命令开启的nginx服务,否则你可以安装nginx安装包存放点:/usr/local/src/nginx配置文件:/usr/local/nginx/nginx.conf项目配置目录:/usr/local/nginx/conf.d/nginx日志目录:/usr/local/nginx/logs/nginxpid文件:/usr/local/nginx/nginx.pidnginx启动文件:/usr/local/nginx/sbin/nginxstartnginxnginx(配置环境变量后即可使用)/usr/local/nginx/sbin/nginxstopnginxnginx-sstop(配置环境变量后即可使用)/usr/local/nginx/sbin/ngin-sstoprestartnginxnginx-sreload(配置后可以使用环境变量)/usr/local/nginx/sbin/nginx-sreloadsystemctl相关命令startnginxservicesystemctlstartnginx.servicestopnginxservicesystemctlstopnginx.servicerestartnginxservicesystemctlrestartnginx.service查看nginxservicesystemctlstatusnginx.servicejoinsystemctlenablenginx.serviceexitsystemctldisablenginx.servicerefreshserviceconfigurationsystemctldaemon-reload查看enabledservicessystemctllist-unit--type=serviceother文章:第二章:PHP安装第三章:Mysql安装和Postgresql安装第四章:Python环境配置相关链接:CentOS7systemd添加自定义系统服务
