致敬!第二次安装nginx。
第一次安装后,放入页面,前端图片总是不出来。经过多次配置nginx.conf文件还是不出来,只得放弃make编译安装形式,从新安装。
先卸载上次安装:
yum remove nginx
whereis nginx
rm -rf 原来的nginx
yum install nginx就成功啦
[root@centos7 html]# pwd
/usr/share/nginx/html
[root@centos7 local]# whereis nginx
nginx: /usr/sbin/nginx
/usr/lib64/nginx
/etc/nginx 配置文件在这里
/usr/share/nginx html前端放这里
/usr/share/man/man8/nginx.8.gz
/usr/share/man/man3/nginx.3pm.gz
[root@centos7 local]# cd /etc/nginx
[root@centos7 nginx]# ls
conf.d fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
default.d fastcgi_params koi-win nginx.conf scgi_params.default win-utf
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
[root@centos7 nginx]# vim nginx.conf
[root@centos7 nginx]# cd /usr/share/nginx
[root@centos7 nginx]# ls
html modules
启动命令 systemctl start nginx
systemctl stop nginx
/etc/nginx 配置文件在这里
/usr/share/nginx html前端放这里
致敬!第一次安装nginx填的坑~~~
nginx安装步骤
下载地址: http://nginx.org/
http://nginx.org/download/nginx-1.16.1.tar.gz 我下载这个版本有点老了
ls -alh 显示文件大小和位置
tar -xzvf nginx-1.16.1.tar.gz 解压软件
cd nginx-1.16.1/
配置: ./configure --prefix=/usr/local/nginx
安装过程如果有没有安装成功的,可以yum update 后再安装
yum install -y zlib-devel openssl openssl-devel
yum -y 回答全部问题为是 , install 向系统中安装一个或多个软件包
再次执行: ./configure --prefix=/usr/local/nginx
make 编译执行
-------这就算安装成功了
启动和配置
nginx在的位置:ls /usr/local/nginx/sbin
=》nginx
输入/usr/local/nginx/sbin/nginx
就代表启动执行了。
我想设置一个环境变量,在输入 nginx 在任何位置都可以执行
cd 回到根目录下
vim .bash_profile复制了其中PATH这一行,然后在下一行写了
PATH=$PATH:/usr/local/nginx/sbin
保存退出wq!
source .bash_profile才可以生效。
再直接输nginx 就可以直接启动啦
ps -ef|grep nginx 查看pid
[root@centos7 ~]# ps -ef|grep nginx
root 58337 1 0 15:47 ? 00:00:00 nginx: master process nginx
nobody 58338 58337 0 15:47 ? 00:00:00 nginx: worker process
nobody 58340 58337 0 15:47 ? 00:00:00 nginx: worker process
nobody 58341 58337 0 15:47 ? 00:00:00 nginx: worker process
nobody 58342 58337 0 15:47 ? 00:00:00 nginx: worker process
root 61503 55254 2 16:29 pts/0 00:00:00 grep --color=auto nginx
[root@centos7 ~]# kill -9 58337 58338 58340 58341 58342
检测是否开启 本地回环检测(这个命令很有用,要记住):
curl http://127.0.0.1
:80 或者:8080
本次出问题一:
防火墙关闭还是端口没有放行不知道,添加了tcp 80端口对外
问题二:
nginx 报403错误
问题出在 : vim /usr/local/nginx/conf/nginx.conf
里面。1.user 后面主进程和工作进程开启人不同。2.server里面没有index.html
这个是我手动加进去的。
下面是解决以上问题,我填坑查的博客。都用到了:
关于Nginx启动成功,浏览器不能访问的解决办法
https://www.shuzhiduo.com/A/obzbqKDjdE/
https://blog.csdn.net/xiannvbushengqi/article/details/105516504
查看是否启动
ps aux|grep nginx
查看端口分配
netstat -ntlp
一切正常啊,那到底情况出在何处呢?
经过查阅了网上的资料,终于找到解决办法
第一步,对80端口进行防火墙配置:
firewall-cmd --zone=public --add-port=80/tcp --permanent
--permanent :当前不生效,重启后生效
第二步,重启防火墙服务:
https://blog.csdn.net/qq_24604781/article/details/125146335
# 重启一个服务
systemctl restart firewalld.service
注意:Centos7 firewalld防火墙开放端口后仍不能访问各自端口,如:Tomcat、ftp和nginx的问题解决
查看当前开了哪些端口其实一个服务对应一个端口,每个服务对应/usr/lib/firewalld/services
下面一个xml
文件
如果 开启了两个服务并放行了对应端口,但是没有绑定http
和ftp
在firewall
中对应的服务(service),则不能通过外网访问搭建的nginx服务器和ftp服务器
(1)可以通过下面这个命令查看可以打开的服务有哪些
firewall-cmd --get-services
(2)可以通过下面的命令添加一个服务到firewalld
firewall-cmd --add-service=http
这样添加的service当前立刻生效,但系统下次启动就失效,可以测试使用。service要永久有效,则加上 --permanent
firewall-cmd --permanent --add-service=http
然后通过systemctl restart firewalld.service重启防火墙就生效了
这个时候就可以通过外网访问搭建的nginx和ftp服务器了
然后重新在浏览器中访问你的ip,应该就可以访问了。
nginx篇-解析nginx多进程问题
https://blog.csdn.net/weixin_44923168/article/details/123403354
vim /usr/local/nginx/conf/nginx.conf
第一行数据就是,把4改成了1.
Nginx 403 forbidden错误的原因以及解决方法
https://www.jb51.net/article/259583.htm
关于Nginx启动成功,浏览器不能访问的解决办法
https://www.shuzhiduo.com/A/obzbqKDjdE/
centos7 远程端口添加防火墙规则报错Error:INVALID_PORT
https://blog.csdn.net/xiannvbushengqi/article/details/105516504
指令: ps
ps -ef|grep nginx
作用: 主要是查看服务器的进程信息
选项含义:
-e:等价于 ‘-A’ ,表示列出全部的进程
-f:显示全部的列(显示全字段)
ps -e 此参数的效果和指定"A"参数相同。
ps f 用ASCII字符显示树状结构,表达程序间的相互关系。
以下这条命令是检查java 进程是否存在:ps -ef |grep java
字段含义如下:
UID PID PPID C STIME TTY TIME CMD
zzw 14124 13991 0 00:38 pts/0 00:00:00 grep --color=auto dae
UID :程序被该 UID 所拥有
PID :就是这个程序的 ID
PPID :则是其上级父程序的ID
C :CPU使用的资源百分比
STIME :系统启动时间
TTY :登入者的终端机位置
TIME :使用掉的CPU时间。
CMD :所下达的是什么指令
1.2 ps -aux | grep命令
ps是显示当前状态处于running的进程,grep表示在这些里搜索,而ps aux是显示所有进程和其状态。
$ ps aux | grep amoeba 查到amoeba的进程
ps aux输出格式:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
格式说明:
USER: 行程拥有者
PID: pid
%CPU: 占用的 CPU 使用率
%MEM: 占用的记忆体使用率
VSZ: 占用的虚拟记忆体大小
RSS: 占用的记忆体大小
TTY: 终端的次要装置号码 (minor device number of tty)
STAT: 该行程的状态,linux的进程有5种状态:
D 不可中断 uninterruptible sleep (usually IO)
R 运行 runnable (on run queue)
S 中断 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process
注: 其它状态还包括W(无驻留页), <(高优先级进程), N(低优先级进程), L(内存锁页).
START: 行程开始时间
TIME: 执行的时间
COMMAND:所执行的指令
- ps a 显示现行终端机下的所有程序,包括其他用户的程序。
2)ps -A 显示所有程序。
3)ps c 列出程序时,显示每个程序真正的指令名称,而不包含路径,参数或常驻服务的标示。
4)ps -e 此参数的效果和指定"A"参数相同。
5)ps e 列出程序时,显示每个程序所使用的环境变量。
6)ps f 用ASCII字符显示树状结构,表达程序间的相互关系。
7)ps -H 显示树状结构,表示程序间的相互关系。
8)ps -N 显示所有的程序,除了执行ps指令终端机下的程序之外。
9)ps s 采用程序信号的格式显示程序状况。
10)ps S 列出程序时,包括已中断的子程序资料。
11)ps -t 指定终端机编号,并列出属于该终端机的程序的状况。
12)ps u 以用户为主的格式来显示程序状况。
13)ps x 显示所有程序,不以终端机来区分。
二、netstat -apn 命令
netstat -anp查看端口占用情况
-a,显示所有
-n,不用别名显示,只用数字显示
-p,显示进程号和进程名
nginx启动命令和停止命令
进入nginx的sbin目录下
cd /usr/local/nginx/sbin/
https://blog.csdn.net/kongfanyu/article/details/128769528
1、启动nginx
./nginx
2、停止nginx两种方式
#待nginx进程处理任务完毕进行停止。
./nginx -s quit
#先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s stop
3、查看nginx端口
ps aux|grep nginx
4、查看nginx版本号
/usr/local/bin » ./nginx -V
nginx version: nginx/1.19.2
built by clang 11.0.3 (clang-1103.0.32.62)
built with OpenSSL 1.1.1g 21 Apr 2020
TLS SNI support enabled
5、重启nginx
a,对 nginx 进行重启先停止再启动,即先执行停止命令再执行启动命令
./nginx -s quit
./nginx
b,重新加载配置文件,当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
6、开机启动
#如果想设开机启动的话
mkdir -p ~/Library/LaunchAgents
cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist(取消开机启动)
7、安装位置、
网站根目录在:/usr/local/var/www
nginx配置文件位置:/usr/local/etc/nginx
注意:nginx被安装到的目录位置:/usr/local/Cellar/nginx
默认端口:80
8、查看帮助
/usr/local/etc/nginx » nginx -h
nginx version: nginx/1.19.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.19.2/)
-c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
9、判断配置文件是否有问题
/usr/local/etc/nginx » nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
10、停止nginx服务的其他的方法
查看nginx进程,进程号,停止的话可以杀进程
查看nginx进程:ps -ef|grep nginx
sudo kill -QUIT //主进程号
sudo kill -TERM //主进程号
/usr/local/etc/nginx » ps -ef|grep nginx
501 3213 1 0 10:00上午 ?? 0:00.00 nginx: master process /Applications/phpstudy/Extensions/Nginx1.16.1/sbin/nginx -p /Applications/phpstudy/Extensions/Nginx1.16.1/
501 3214 3213 0 10:00上午 ?? 0:00.01 nginx: worker process
501 3215 3213 0 10:00上午 ?? 0:00.01 nginx: worker process
501 3216 3213 0 10:00上午 ?? 0:00.05 nginx: worker process
501 3217 3213 0 10:00上午 ?? 0:00.02 nginx: worker process
501 7114 6417 0 11:02上午 ttys001 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn nginx
/usr/local/etc/nginx »
nginx配置SSL
Nginx 配置 SSL,很系统!很完整!解决 Nginx 报错 nginx: [emerg] unknown directive “ssl” in /usr/local/nginx/conf/nginx.conf
完整记录在给 Nginx 配置 SSL 操作,起初的 Nginx 配置未引入SSL模块,现配置 SSL 遇到的问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)