Skip to content

Latest commit

 

History

History
122 lines (105 loc) · 2.86 KB

nginx.md

File metadata and controls

122 lines (105 loc) · 2.86 KB

nginx

设置账号密码

参考

server
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name demo.example.com;


    # Geth proxy that password protects the public Internet endpoint
    location /eth
        auth_basic "Restricted access to this site";
        auth_basic_user_file /etc/nginx/protected.htpasswd;

        # Proxy to geth note that is bind to localhost port
        proxy_pass http://localhost:8545;


    # Server DApp static files
    location /
        root /usr/share/nginx/html;
        index index.html

        auth_basic "Restricted access to this site";
        auth_basic_user_file /etc/nginx/protected.htpasswd;

生成密码

sudo htpasswd -c /etc/nginx/protected.htpasswd demo

安装

./configure --prefix=/home/wangx/nginx/
make
make install

为什么这么快

为什么快,我觉得nginx可以什么都不处理啊。仅仅是一个路由器,能不快吗

配置

  • 配置socket
location /ws {
    proxy_pass http://socket.ramwin.com/ws;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}
  • 配置路径
location /media_url/ {
    # internal;  # 这个可以让这个url必须内部django返回才处理
    alias /var/www/media/;
}
  • 使用变量
set ROOT=/home/web/djangoproject
location /django_media {
    alias ${ROOT}/django_media
}
  • 代理到socks
upstream site {
    server unix:<file.sock>
}
server {
    location /api {
        proxy_pass http://site;
        proxy_set_header Host $host;
        proxy_set_header X_FORWARDED_PROTO $schema;
        # 把 https 传给proxy 这样django可以通过设置
        # SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') 来知道是否用了https
    }
}
  • gzip压缩
server {
    gzip on;
    gzip_comp_level 6;
    gzip_types text/markdown text/css text/plain text/javascript application/javascript;
}
  • 目录访问
server {
    location / {
        try_files $uri $uri/ =404;
        autoindex on;
    }
}
server {
    listen 80 default_server;

    server_name ramwin.com;

    return 301 https://$host$request_uri;
}