安装、配置、使用nginx
程序员文章站
2022-06-11 16:35:20
...
1.使用yum install nginx命令进行安装
2.安装完成后,配置文件路径位于 /etc/nginx/nginx.conf
参考配置例子
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name appgw.livibank.com;
location / {
proxy_pass http://192.168.0.242:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
server_name appgw.livibank.com
这个是方便可以通过域名转发到不同的服务器(前提是需要配置一下host,ip为nginx所在的机器ip,域名就是server_name配置的域名)
3.nginx启动命令 nginx
4.重启命令 nginx -s reload
-------------------------------------------------------------------------------------
上面那一种是通过server_name域名匹配,还有一种根据location匹配,例如
server {
listen 80;
location /appgw/ {
proxy_pass http://192.168.0.242:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
请求时候,例如http://124.250.83.1:80/appgw/cocgw/4401,注意当转发到目标ip时候,appgw会截去,即目标机器收到的请求时
192.168.0.242:8080/cocgw/4401
上一篇: php+iframe实现隐藏无刷新上传文件_php实例
下一篇: 一个thinkphp入门级问题
推荐阅读
-
centos环境下lnmp安装配置
-
使用光盘配置本地yum源的方法 yum源配置
-
Ubuntu安装MySQL5.7并配置数据存储路径的方法步骤
-
CentOS 6.1 环境中部署nginx、php(包括fastcgi)、虚拟主机配置
-
详解Linux下JDK、Tomcat的安装及配置
-
Python网页解析利器BeautifulSoup安装使用介绍
-
函数中使用require_once问题深入探讨 优雅的配置文件定义方法推荐
-
Marmoset Toolbag怎么使用?Marmoset Toolbag 3安装+使用教程(附破解文件下载)
-
MineSight怎么使用?MineSight 3D安装+使用教程
-
Anaconda安装及简单使用