在腾讯云上部署nginx

来源:互联网 发布:阿里云服务器代购 编辑:程序博客网 时间:2024/05/19 23:54

wget url

yum install gcc gcc-c++ autoconf automake

yun -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel (安装依赖zlib、openssl和pcre)

创建启动nginx的进程用户:
groupadd nginx
useradd -r -g nginx nginx

Linux下各种依赖都已经安装,是因为没有找到makefile。
如果是自己写的,确定在当前目录下;如果是源码安装,先运行./configure,生成makefile,再执行make,即可正常运行

make && make install

配置写入:
–with-xxx 代表默认没有打开的功能
–without-xxx 代表默认打开的功能

–prefix=path 代表安装路径
–sbin-path=path sbin路径
–conf-path 配置文件
–pid-path 代表进程号保存文件
–error-log-path错误日志
–lock-path 锁文件
–user ps看到的启动进程用户
–group ps看到的启动进程用户所在组
–with-http_ssl_module
–with-http_flv_module
不写为默认

sed -e "s|%%PREFIX%%|/usr/local/nginx|" \    -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \    -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|"     -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" 

启动 cd /usr/local/nginx/sbin
./nginx

出现80端口占用的问题

检查: Nginx是否配置正确:
./nginx/sbin/nginx -t
Nginx是否成功启动:
ps -ef | grep nginx,查看是否有Nginx的进程
netstat -ntl,查看是否有80端口
Ping测试连通性:
ping x.x.x.x (ip地址)
Telnet测试端口是否可用:
telnet x.x.x.x 80
原因:腾讯云默认80未开放
在腾讯云安全组开放80端口:
在云服务器-安全组,
编辑规则
最后记得在该规则里添加该云主机,在规则->管理云主机->将云主机添加进去
这里写图片描述

出现系统程序占用80端口的问题?
/usr/local/nginx 下的conf中修改 server的监听端口为880
或者
losf -i:80 查出占用端口的程序
为httpd
service httpd stop 关闭服务
service httpd status 查看是否成功关闭
find /etc/httpd/ -name *conf 查找httpd配置文件的位置
vim /etc/httpd/conf/httpd.conf 编辑文件 –修改Listen 为你想要的为使用的如881–wq保存退出
service httpd start 启动服务

检查配置文件是否正确
cd /usr/nginx/sbin/
./nginx -t
重启nginx
/usr/nginx/sbin/nginx -s reload

查看hosts 文件 cat /etc/hosts,修改hosts文件 vi /etc/hosts

原创粉丝点击