ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

nginx搭建web服务器,配置端口复用

2021-04-04 21:51:32  阅读:172  来源: 互联网

标签:web 配置文件 stop 复用 server nginx usr local


1、文件安装目录说明

Nginx安装目录为/usr/local/nginx
Nginx主配置文件目录为/usr/local/nginx/conf/nginx.conf
https密钥key存放目录/usr/local/nginx/sslkey/vhost*
网站存放目录/usr/local/nginx/WebServer
各网站主配置文件存放目录/usr/local/nginx/WebServer/vhost*.conf

微信图片_20210404212045.png


2、Nginx主配置文件

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;                 #业务监听端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
     include /usr/local/nginx/WebServer/*.conf;                 #外链加载的主Nginx的配置文件路径,需要指向到各个网站的配置文件上去
}

3、各网站主配置文件的解释

server {
     listen       80;
     server_name  www.secddi.com;       #此处为需要重写的URL地址
     rewrite ^(.*) https://$server_name$1 permanent;
}                                     #以上配置文件的意思为重写服务器的http 80端口至https 443端口
server {
	listen 443;
	server_name www.secddi.com;        #此处为https的URL地址
        index index.html;
        root /usr/local/nginx/WebServer/vhostA;        #此处为web网站的访问目录,主页路径
        ssl_certificate      /usr/local/nginx/sslkey/vhostA/full_chain.pem;        #此处为配置的https证书路径
        ssl_certificate_key  /usr/local/nginx/sslkey/vhostA/private.key;           #此处为配置的https证书路径
	ssl_session_cache    shared:SSL:1m;
	ssl_session_timeout  5m;
	server_tokens off;
	fastcgi_param   HTTPS               on;
	fastcgi_param   HTTP_SCHEME         https;
	access_log /usr/local/nginx/logs/httpsaccess.log;
}

4、配置nginx脚本

#!/bin/bash
#description: Ngnix Service
#chkconfig:2345 88 77 
#帮助函数
Usage (){
echo $"Usage:$0 {start|stop|restart}"
}

#启动函数
start(){

pid_file="/usr/local/nginx/logs/nginx.pid"
if [ -f $pid_file ];then
   echo "Ngnix Already Running, Do Not Run Again.。"
   exit 1
else
   echo "Ngnix Service Is Start Running..."
    /usr/local/nginx/sbin/./nginx
	/usr/local/nginx/sbin/./nginx -s reload
fi

}

#停止函数
stop(){
pid_file="/usr/local/nginx/logs/nginx.pid"
if [ -f $pid_file ];then
    echo "Ngnix coming to stop running"
	/usr/local/nginx/sbin/./nginx -s stop
else
   echo "Ngnix is not running..."
   exit 1

fi
}

#选择语句
case $1 in
	start )
	  start
	;;
	stop )
	  stop
	;;
	restart )
	  stop
            sleep 1
	  start
	;;	
	* )
	Usage
	;;
esac

5、将配置文件保存在/etc/init.d/nginx位置即可。之后即可通过下面的命令进行启动服务。

chmod +777 /etc/init.d/nginx 
/etc/init.d/nginx stop/start/restart

标签:web,配置文件,stop,复用,server,nginx,usr,local
来源: https://blog.51cto.com/eholog/2685047

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有