Skip to content

nginx 配置记录

注意

这是以前老代码提取的,仅仅供参考!

301 形式

 server {
        listen       80;       # 配置监听的端口
        server_name q123q.cc www.q123q.cc;    # 配置的域名

        location / {
          return 301 https://$server_name$request_uri;
        }

}


server {
        listen       443 ssl;
        server_name  q123q.cc www.q123q.cc;

        ssl_certificate      /root/card/ali.pem;
        ssl_certificate_key  /root/card/ali.key;

        # vue 2.x 版本的工具
        location / {
           root /var/www/project-tools/dist;
           try_files $uri $uri/ /index.html;
        }
}

重定向

server {
    listen 80;
    server_name localhost;
    return 301 https://127.0.0.1$request_uri;
}

server {
    listen 80;
    server_name localhost;
    rewrite ^(.*)$ https://$host$1 permanent;
}

区别 https://blog.nginx.org/blog/creating-nginx-rewrite-rules

忘了。。

home 之前 是直接指向 ngc 的 home.html

  location / {
        root $my_path/html;
        try_files $uri $uri/ /home.html;
        index /home.html;
    }

server 部署

server {
    listen 80;
    listen [::]:80;

    server_name dist.q123q.cc;


    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://127.0.0.1:2002$request_uri;
    }

}

代理

server {
    listen 80;
    listen [::]:80;

    server_name g.q123q.cc;

    location / {
      proxy_pass http://139.186.203.160:3000$request_uri;
    }

}

Https

nginx

server {
    listen 80;
    listen [::]:80;

    server_name liuyu.q123q.cc;

    #将请求转成https
    rewrite ^(.*)$ https://$host$1 permanent;
}

server {
    #监听443端口
    listen 443;

    #你的域名
    server_name liuyu.q123q.cc;

    ssl on;
    #ssl证书的pem文件路径
    ssl_certificate  /myopt/ssl/liuyu.pem;
    #ssl证书的key文件路径
    ssl_certificate_key /myopt/ssl/liuyu.key;

    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://127.0.0.1:2001$request_uri;
    }
}