nginx在linux下的部署配置
2021/10/26 7:11:00
本文主要是介绍nginx在linux下的部署配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一、nginx部署
依赖库的安装包下载:
yum install -y pcre pcre-devel yum install -y zlib zlib-devel yum install -y openssl openssl-devel
【pcre zlib openssl】 也可以提前下载安装包进行离线安装。
https://pkgs.org/https://pkgs.org/
nginx源码包下载:https://nginx.org/en/download.htmlhttps://nginx.org/en/download.html
下载完成后,执行解压缩、配置、编译、安装命令:
# tar zxvf nginx-1.20.1.tar.gz # ./configure # make # make install
安装成功后,查看nginx支持命令:
[root@ ~]# /usr/local/nginx/sbin/nginx -h nginx version: nginx/1.20.1 Usage: nginx [-?hvVtTq] [-s signal] [-p prefix] [-e filename] [-c filename] [-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/nginx/) -e filename : set error log file (default: logs/error.log) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
常用命令: | |
启动nginx | /usr/local/nginx/sbin/nginx |
停止nginx | /usr/local/nginx/sbin/nginx -s stop |
重新加载配置 | /usr/local/nginx/sbin/nginx -s reload |
测试配置的完整性 | /usr/local/nginx/sbin/nginx -t |
二、nginx配置
使用默认配置文件:/usr/local/nginx/conf/nginx.conf
例子:为了解决10.0.0.9的HTTP服务无法被外部访问的问题,通过开放server(10.0.0.1)部署nginx,然后通过代理间接访问10.0.0.9的http服务。
(代理10.0.0.9的54321【HTTP】端口)
#user nginx; worker_processes 10; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; worker_rlimit_nofile 307200; events { use epoll; worker_connections 40460; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; access_log /var/log/nginx/access.log main; location / { root html; index index.html index.htm; } } server { listen 80; server_name mysql.com; access_log /var/log/nginx/access.log main; location / { proxy_pass http://10.0.0.9:54321/; proxy_redirect default; } location /phpmyadmin/ { proxy_pass http://10.0.0.9:54321/phpmyadmin/; proxy_redirect default; } } }
本地主机绑定host: 10.0.0.1 mysql.com
然后访问mysql页面: http://mysql.com/phpmyadmin/
这篇关于nginx在linux下的部署配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-13用Nginx防范DDoS攻击的那些事儿
- 2024-12-13用Terraform在AWS上搭建简单NGINX服务器指南
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享