Linux安装Nginx

1.做 html文件

gitbook 把markdown生成html文件

2. 上传html文件

推荐:使用支持sftp协议的工具上传 ssh2协议

例如:pycharm、filezilla等

3. 使用Nginx提供HTML浏览服务

Nginx:可以当做HTTP服务器,提供HTML的传输服务

修改配置文件

vi /etc/nginx/nginx.conf

建议将server 单独拿出来,然后加入include /etc/nginx/sites-avilable/*.conf; (配置.conf的路径)

这样可以在上面的配置地址中写多个server文件

user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/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;
    include /etc/nginx/sites-avilable/*.conf;  
}

user 启动的用户(权限)

server.conf 举例

server {
    listen 4000  ;  # 监听的端口
    server_name  build.2222.com; # 域名解析
    charset utf-8;    #
    client_max_body_size 200m;
    access_log  /var/log/nginx/git-access.log;
    error_log  /var/log/nginx/git-err.log;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        #静态文件如js,css的存放目录
        alias /home/myb/MyNotes/MyNotes/_book;
    }
    location / {
        proxy_pass http://127.0.0.1:4000; # 这里要配合启动文件使用
        proxy_redirect     off;
        proxy_set_header   Host                 $http_host;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For      $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto    $scheme;
    }
}
server 中的

root 路径(修改为自己想公开的)

charset utf-8 (中文乱码时使用)

nginx -s reload 刷新nginx(一般为修改过配置文件后使用)

遇见Nginx 403报错时,将nginx的配置文件中的 user 改为 root 然后刷新Nginx,但是不建议

反向代理:隐藏server,用户可以访问server,但是不知道谁提供的server,ngin可以进行路由分发,将请求分给不同的服务器

正向代理:隐藏client,用户访问server时隐藏,不知道是谁访问的server

Nginx优点

1、处理静态网页性能非常好

2、可以进行反向代理

Nginx命令

nginx直接启动        nginx
systemctl命令启动    systemctl start nginx.service
查看启动后记录        ps aux | grep nginx
重启Nginx服务        systemctl restart nginx.service
重新载入配置文件      netstat -tlnp
查看端口号           netstat -tlnp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值