前提:nginx 已安装
简介:nginx(engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。国内分支Tengine。
部署:进入安装的 nginx 目录,找到 nginx.conf 文件(查找命令:)
查找命令:find / -name nginx.conf
找对自己要编辑的 nginx.config 文件
进入对应目录,编辑文件:vim nginx.conf :
下面是我的配置:
说明:由于默认 端口80 被占用,需重新配置一个 server 服务,此处设置了不同的端口。设置如下:
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 65; #gzip on; include /etc/nginx/conf.d/*.conf;
# 新添加部分:由于默认端口被占用,需重新配置一个 server 服务,此处设置了不同的端口。 server { listen 6789; # 前端显示的 port server_name localhost; # 服务器地址 root /usr/local/network_xx/web; # 文件存放的地址,也就是 前端代码(一般是index.html+其他前端所有的文件放置的) 放置的目录地址 index index.html; # 入口文件 charset utf-8; # 编码 access_log /var/log/nginx/access.log; # 使用日志,地址与默认地址保持一致 error_log /var/log/nginx/error.log; # 错误日志,地址与默认地址保持一致 } }
参考如下:
// 参考: server { listen 80; server_name localhost; location / { proxy_pass http://www.baidu.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
配置完成后,需要重新加载启动。
1. nginx -s stop 2. nginx -c ../../../nginx.conf // 自己的 nginx.conf 路径 3. nginx -s reload nginx 启动: 直接 nginx 即可 更多命令:nginx 使用手册,查看手册命令: man nginx