[root@localhost ~]# curl -i localhost
效果如下:
······
Welcome to nginx!。
······
7.nginx配置文件位置在/etc/nginx/
[root@localhost /]# ll /etc/nginx/ 总用量 32 drwxr-xr-x. 2 root root 25 10月 12 13:11 conf.d -rw-r--r--. 1 root root 1007 5月 31 22:09 fastcgi_params -rw-r--r--. 1 root root 2837 5月 31 22:09 koi-utf -rw-r--r--. 1 root root 2223 5月 31 22:09 koi-win -rw-r--r--. 1 root root 3957 5月 31 22:09 mime.types lrwxrwxrwx. 1 root root 29 10月 12 13:11 modules -> ../../usr/lib64/nginx/modules -rw-r--r--. 1 root root 643 5月 31 22:08 nginx.conf -rw-r--r--. 1 root root 636 5月 31 22:09 scgi_params -rw-r--r--. 1 root root 664 5月 31 22:09 uwsgi_params -rw-r--r--. 1 root root 3610 5月 31 22:09 win-utf
8.实践:
目的:修改服务名,接着从外部访问这个服务
操作:
a.修改nginx配置文件
[root@localhost nginx]# vim /etc/nginx/conf.d/default.conf
修改server_name部分:server_name yytest.com;
b.重载服务
[root@localhost nginx]# /usr/sbin/nginx -s reload
c.从外部访问nginx服务(192.168.10.11)
如在客户机(192.168.10.10)的浏览器访问:http://yytest.com
d.你发现访问不了,原因1,你没有在hosts文件做映射;原因2,及时你在hosts文件中了映射,由于nginx服务器的80端口堵塞或防火墙没关
e.解决办法:
步骤一:修改客户机(192.168.10.10)的hosts文件,使用SwitchHosts工具添加 192.168.10.11 yytest.com
步骤二:关闭防火墙,具体下文有说明
9.nginx常用操作
启动:
$ /usr/sbin/nginx或任意路径下运行service nginx start(centos7是systemctl start nginx.service )
重启:
$ /usr/sbin/nginx –s reload
停止:
$ /usr/sbin/nginx –s stop
测试配置文件是否正常:
$ /usr/sbin/nginx –t
可能遇到的问题:
具体情况如下 1。本机能ping通虚拟机 2。虚拟机也能ping通本机 3。虚拟机能访问自己的web 4。本机无法访问虚拟己的web 这个问题的原因是服务器的80端口没有打开或防火墙没有关闭
解决办法
如果是centos6:
解决方法如下:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
然后保存:
/etc/rc.d/init.d/iptables save
重启防火墙
/etc/init.d/iptables restart








