栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx实现网站发布

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx实现网站发布

Nginx Nginx部署 1 CentOS 6(yum源)

wget -O /etc/yum.repos.d/CentOS-Base.repo http://files.tttidc.com/centos6/Centos-6.repo

wget -O /etc/yum.repos.d/epel.repo http://files.tttidc.com/centos6/epel-6.repo

yum makecache

yum -y install gcc zlib zlib-devel pcre pcre-devel openssl openssl-devel

2 nginx-1.10.1.tar.gz

wget http://nginx.org/download/nginx-1.10.1.tar.gz

tar -zxvf nginx-1.10.1.tar.gz

cd nginx-1.10.1

在 nginx-1.10.1 目录下执行configure配置进行编译
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

在 nginx-1.10.1 目录下进行安装
make && make install

cd /usr/local/nginx

编辑防火墙开放80端口
vi /etc/sysconfig/iptables

加入内容并保存:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙
/etc/init.d/iptables restart

或者关闭防火墙
service iptables stop

或者永久关闭防火墙
chkconfig iptables off

Nginx开机自启动

编辑
vim /etc/init.d/nginx

直接覆盖:

#nx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;

*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

保存后,执行
chmod a+x /etc/init.d/nginx

这样之后就可以通过以下命令进行控制Nginx
/etc/init.d/nginx start
/etc/init.d/nginx stop

将nginx服务加入chkconfig管理列表
chkconfig --add /etc/init.d/nginx

这样之后就可以通过以下命令进行控制Nginx
service nginx start
service nginx stop
service nginx restart

最后设置开机自动启动
chkconfig nginx on

网站发布
  1. 将网站部署到服务器,浏览器通过URL地址访问页面
  2. 在地址栏输入URL地址,访问服务器上的页面。
1 Nginx服务器概述

Nginx是一种服务器软件,其最主要,最基本的功能是可以与服务器硬件(电脑)结合,让程序员可以将程序发布在Nginx服务器上,让成千上万的用户可以浏览。

​ 除此之外,Nginx还是一种高性能的HTTP和反向代理服务器,同时也是一个代理邮件服务器。也就是说,我们在Nginx上可以:

  1. 可以发布网站(静态, html,css,js)
  2. 可以实现负载均衡,
  3. 代理服务器
  4. 可以作为邮件服务器实现收发邮件等功能
2 Nginx实现项目发布
  1. 路径:修改 C:WindowsSystem32driversetc 下的hosts,实现Windows浏览器访问Linux下Nginx部署的页面。(实现Windows下的域名解析)
Linux修改Nginx虚拟主机配置

修改配置文件
vim /usr/local/nginx/conf/nginx.conf

 server {
        listen       80;    		#端口号
        server_name   localhost;   	#域名ip
        location / {                #项目路径定位
         root     html;				#指定项目所在目录
         index   index.html index.htm;  # 定位打开指定目录下的index.html 或者 index.htm
}}

修改端口号
listen 81;
重新加载Nginx服务后,并输入本机ip:81访问。
/usr/local/nginx/sbin/nginx -s reload

修改域名
server_name www.Lnginx.com;
需要编辑 hosts 实现域名解析
vim /etc/hosts 添加 回送地址+域名 虚拟主机地址+域名
重新加载Nginx服务
/usr/local/nginx/sbin/nginx -s reload

定义项目路径
root /var/www/html;
index index.html;
当访问时,就会访问 /var/www/html/ index.html
重新加载Nginx服务
/usr/local/nginx/sbin/nginx -s reload

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/888327.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号