Nginx 配置摘记 - litonghui/TechBlog GitHub Wiki
在使用nginx 时候出现问题,记录一下。
1.在/etc/init.d/ 文件下找不到 nging bash 脚本,具体体现执行结果如下
[@sjs_232_143 init.d]# service nginx start
Redirecting to /bin/systemctl start nginx.service
解决办法,重定向启动nginx:
[@sjs_232_143 init.d]# systemctl -l enable nginx
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service'
[@sjs_232_143 init.d]# systemctl -l start nginx
[@sjs_232_143 init.d]# service nginx start
Redirecting to /bin/systemctl start nginx.service
[@sjs_232_143 init.d]#
2. 查看nginx 安装路径:
[@sjs_232_143 ~]# ps -ef|grep nginx
root 2530 1 0 May19 ? 00:00:00 nginx: master process /usr/sbin nginx -c /etc/nginx/nginx.conf
root 15437 12435 0 15:29 pts/1 00:00:00 grep --color=auto nginx
nginx 16551 2530 0 May19 ? 00:00:07 nginx: worker process
其中master process 中的/etc/nginx 为nginx 的安装路径。
3. 其中 /nginx/conf(conf.d) 为配置文件目录;/nginx/nginx.conf 主配置文件,进入主配置文件 vim nginx.conf
# 定义Nginx 运行的用户和用户组
user nginx;
# 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指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改 成off。
sendfile on;
#tcp_nopush on;
# 长连接时间
keepalive_timeout 65;
#gzip on;
# 虚拟机配置
include /etc/nginx/conf.d/*.conf;
}
4. 关于nginx 虚拟机配置 cd /nginx/conf.d目录下的所有配置文件,例如:
[@sjs_232_143 nginx]# cd conf.d
[@sjs_232_143 conf.d]# ls
@ default.conf gerrit.conf jenkins.conf m-icall.conf node.com.conf
其中vim node.com.conf:
upstream riki {
server 127.0.0.1:3000;
}
upstream jenkins {
server 127.0.0.1:8089;
}
server {
listen 80 default_server;
#host 代理
server_name lth.sogou localhost;
location / {
# 反向代理,node
proxy_pass http://riki;
}
# 反向代理,jenkins
location /jenkins{
proxy_pass http://jenkins;
}
}
其实查看default.conf 文件,发现如下,二级域名为/meizi ,如果默认没有二级域名,则依然会代理到http://127.0.0.1:3000
location /meizi{
proxy_pass http://127.0.0.1:3000;
}