nginx问题清单

nginx常用命令

refer link

nginx的安装以及启动

安装:reference link—菜鸟教程

nginx常用命令
/usr/local/nginx/sbin/nginx -s reload # 重新载入配置文件
/usr/local/nginx/sbin/nginx -s reopen # 重启 Nginx
/usr/local/nginx/sbin/nginx -s stop # 停止 Nginx

启动:

find / -name nginx
/usr/local/nginx/sbin/nginx
ps -ef|grep nginx
在这里插入图片描述

配置nginx开机自启:

vim /etc/rc.d/rc.local

touch /var/lock/subsys/local
/usr/bin/fdfs_tracked /etc/fdfs/tracker.conf restart
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf restart
/usr/local/nginx/sbin/nginx

开启nginx的日志

我有一个这样的配置
location /test {
alias /home/lmj/;
index test.html;
}
在这里插入图片描述
查看报错日志:
vim /usr/local/nginx/logs/error.log
“/home/lmj/” failed (13: Permission denied)
开启资源访问的权限
chmod 777 /home/lmj chmod 777 /home/lmj/test.html
安装时指定nginx的安装目录
./configure --prefix=/xx/xx

–with-debug enable debug logging
–modules-path=PATH set modules path
–with-select_module enable select module
–without-select_module disable select module


nginx配置语法

配置文件由指令和指令构成
每条指令以;结束
include允许组合多个配置文件
使用$使用变量


  • localtion是一个url表达式

  • nginx命令行
    -s 向系统发信号 请求stop/还是restart或者reload
    -t 检测配置文件。
    -c是指定配置文件

nginx配置:server_name的作用

https://blog.csdn.net/cheng_kohui/article/details/82930464

nginx日志级别

debug > info > notice > warn > error > crit > alert > emerg

access_log logs/access.log main;

log_format main

配置日志的输出格式
https://blog.csdn.net/czlun/article/details/73251723

解决重启问题

vim /usr/local/nginx/conf/nginx.conf
在这里插入图片描述
mkdir /usr/local/nginx/logs
cp /var/run/nginx/nginx.pid /usr/local/nginx/logs/

nginx -c /alidata/server/nginx/conf/nginx.conf

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

如何查看安装Nginx时的编译选项

通过/opt/nginx/sbin/nginx -V命令可以查看安装Nginx时的编译选项

nginx反向代理和负载均衡的配置

检查配置文件nginx.conf的正确性命令:

/usr/local/nginx/conf/nginx.conf -t
编辑配置文件
vim /usr/local/nginx/conf/nginx.conf
在这里插入图片描述


    upstream testRedisson{
        server 192.168.43.107:8082 weight=3;
        server 192.168.43.107:8083 weight=3;
        server 192.168.43.107:8084 weight=3;
     }

    server {
        listen       80;
        server_name  localhost;
		#server_name  192.168.0.200; 二者是等价的,如果你的应用和nginx在同一服务器,则浏览器访问localhost即可
        #如果不在同一服务器,则需访问192.168.0.200

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

          location /testRedisson {
             proxy_pass http://testRedisson;
             index  index.html  index.htm;
         }
          
         location /group1/M00/ {
           ngx_fastdfs_module;
        }

@RequestMapping(“testRedisson”)

浏览器访问 http://192.168.43.14/testRedisson
有负载均衡,请求会被随机分配到8082,8083,8084端口,转发后的路径如下:
http://192.168.43.107:8082/testRedisson
http://192.168.43.107:8083/testRedisson
http://192.168.43.107:8084/testRedisson
https://www.jianshu.com/p/5caa48664da5

nginx配置注解版

#配置用户,最大连接数,日志级别   ----主模块命令
#user  nobody;  #指定Nginx Worker进程运行用户以及用户组
worker_processes  1;     #指定nginx进程数,一般为1 每个Nginx进程平均耗费10M~12M内存。建议指定和CPU的数量一致即可。

#error_log  logs/error.log;            #定义全局错误日志文件debug>info>notice>warn>error
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;       #这是一个以nginx的安装路径作为参考的相对位置。 我的在/usr/local/nginx/logs/error.log

pid        logs/nginx.pid;          #指定nginx进程号(pid)文件的存储位置

events {
    worker_connections  1024;    #nginx的最大连接数是1024  ---事件指令
}


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"';
					  
					  #用于指定Nginx日志的输出格式。main为此日志输出格式的名称,可以在下面的access_log指令中引用。

     access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;    #开启GZIP压缩,实时压缩输出数据流,加速前后端数据的传输
	#server {
		#	listen 80;   
		#	server_name 192.168.8.18 cszhi.com;       #指定IP地址或者域名,多个域名之间用空格分 开
		#	charset utf8;                          #设置网页的默认编码格式
		#	access_log logs/www.ixdba.net.access.log main;   #指定此虚拟主机的访问日志存放路径,main是一个格式变量
 
					 #location / {   
                     # alias test/          ## 相当于location /test/{}					 
					 #	index index.html index.htm index.php;     #index用于设定访问的默认首页地址
					 #	root /wwwroot/www.cszhi.com              #root指令用于指定虚拟主机的网页根目录,可相对/绝对
					 #   autoindex on;        #树形结构展示网站目录
					 #}
				   
					  # location /group1/M00/ {
					  #    ngx_fastdfs_module;          #用来整合fastdfs分布式文件服务器的
					  # }
		#}
		server {
			listen 80;   
			server_name localhost
			charset utf8;                         
			access_log logs/test.log main; 
			
			   location / {                                 
				 root html;                                 
				 index index.html;
			   }
			   
			   location /test { 
				  alias	/home/lmj/;                                 
				  index test.html;
			   }
			   
        # 遇到500请求,进行页面重定向
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

         
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    #配置负载均衡
    #upstream cszhi.com{
	#ip_hash;  # fair根据后端服务器的响应时间来分配请求/ url_hash:按访问url的hash结果来分配请求/ip_hash:每个请求按访问IP的hash结果分配/轮询(默认):每个请求按时间顺序逐一分配到不同的后端服务器
	#server 192.168.8.11:80;   #可以设定每个后端服务器在负载均衡调度中的状态
	#server 192.168.8.12:80 down; #表示当前的server暂时不参与负载均衡/backup:预留的备份机器/max_fails:允许请求失败的次数,默认为1/fail_timeout:在经历了max_fails次失败后,暂停服务的时间
	#server 192.168.8.13:8009 max_fails=3 fail_timeout=20s;
    #}
	#通常在结合一下实现负载均衡和方向代理
  #	server {
       # listen       80;
       # server_name  localhost;

      #  location /hi {
    #        proxy_pass http://cszhi.com;   代理转发
    #    }
   # }
   # 访问http://localhost/hi,proxy模块会将请求转发到127.0.0.1的8001端口上
    #配置ssl证书,其实就是https证书
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;        
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;          root目录就是nginx的解压目录,这里是配置/路径下的允许访问的静态资源 。(对外开放静态资源)
    #        index  index.html index.htm;
    #    }
    #}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值