nginx搭建web服务器,配置端口复用
2021-04-04 21:36
1121 查看
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
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
相关文章推荐
- linux学习笔记——搭建基于nginx的web服务器、多核配置、nginx配置参数
- 教程 | 用安卓手机搭建 web 服务器(二)—— Nginx 安装配置
- Nginx + Apache+pure-ftpd 搭建高负载Web服务器(完整版)
- 在Web服务器上配置SSL来验证CA服务器的搭建过程
- nginx web服务器概念了解 配置
- Android 小白 的 学习之路 之 阿里云上 Tomcat Web服务器的搭建以及配置
- nginx服务器简单搭建配置
- 高性能Web服务器Nginx的配置与部署研究
- 高性能Web服务器Nginx的配置与部署研究(4)Nginx常用命令
- Nginx搭建web服务器
- 高性能Web服务器Nginx的配置与部署研究(7)核心模块之主模块的非测试常用指令
- Centos5.4+Nginx-0.8.50+UWSGI-0.9.6.2+Django-1.2.3搭建高性能WEB服务器
- 高性能Web服务器Nginx的配置与部署研究(10)核心模块之HTTP模块Location相关指令
- 轻松使用Nginx搭建web服务器
- Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建高性能Web服务器
- Linux服务器配置——搭建WEB服务器
- Ubuntu搭建web服务器系列之Tomcat(JDK+Tomcat+MySQL+Nginx+Red
- NodeMCU入门(4):搭建Web服务器,配置网络连接
- 利用不同端口为本地nginx服务器配置多个站点
- 高性能Web服务器Nginx的配置与部署研究(10)核心模块之HTTP模块Location相关指令