基础部分设置

[root@centos ~]# vim /opt/nginx/conf/nginx.conf

user www www;
worker_processes auto;
pid logs/nginx.pid;
worker_rlimit_nofile 100000;

events {
use epoll;
multi_accept on;
worker_connections 65535 ;
}

http {

include mime.types;
default_type application/octet-stream;
charset utf-8;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 64k;
client_max_body_size 8m;

server_tokens off;
sendfile on;

keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;

limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;

tcp_nopush on;
tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;

gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_min_length 5k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;

include /opt/nginx/conf/vhosts/*.conf;

}

1. 支持HTTPS,并且必须强制https方式打开(必须拥有域名)

[root@centos ~]# vim /opt/nginx/conf/vhost/www.vicowong.com.conf

server{
listen 80;
server_name ~^(?<subdomain>.+)\.vicowong\.com$;
rewrite ^/(.*) http://www.vicowong.com/$subdomain/$1 permanent;
}

server {
set $domain www.vicowong.com;
set $web_dir /data/website/$domain;
set $log_dir /data/logs/;

server_name www.vicowong.com m.vicowong.com api.vicowong.com admin.vicowong.com;
listen 443 ssl http2;
ssl_certificate /data/ssl/startssl.crt;
ssl_certificate_key /data/ssl/startssl.key;
ssl on;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
# ssl_ciphers 'AES128+EECDH:AES128+EDH:!aNULL';
ssl_prefer_server_ciphers on;
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.4.4 8.8.8.8 valid=300s;
resolver_timeout 10s;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
# add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;

access_log off;
# access_log $log_dir$domain.access.log;
error_log $log_dir$domain.error.log;

root $web_dir;
location = / {
if ($host = 'www.vicowong.com') {
return 301 https://$host/blog/index.htm;
}
if ($host != 'www.vicowong.com') {
return 301 https://$host/index.php;
}
}
location / {
index index.htm;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $web_dir/$fastcgi_script_name;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;

}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root $web_dir;
expires 30d;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
}
server {
listen 80;
server_name www.vicowong.com m.vicowong.com api.vicowong.com admin.vicowong.com;

location = / {
if ($host = 'www.vicowong.com') {
return 301 https://$host/blog/index.htm;
}
if ($host != 'www.vicowong.com') {
return 301 https://$host/index.php;
}
}
location / {
if (!-e $request_filename) {
return 301 https://$host$request_uri;
}
}
}

1. 支持laravel

server {
  listen 80;
  server_name 192.168.1.10;
  set $root_dir /data/www/blog/public/;

root $root_dir;

location / {
    index index.html index.php;
    try_files $uri $uri/ /index.php?$query_string;
  }

location ~ \.php {
    root $root_dir;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }
}

2. 支持thinkphp

server {
listen 80;
server_name 192.168.1.10;

root /data/www/web;

location / {
index index.html index.php;

# for bowers thinkphp without /index.php path
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php {
root /data/www/web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

# for thinkphp pathinfo mode
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}

3. 支持nodejs

server {
set $domain www.vicowong.com;
set $web_dir /data/website/$domain;
set $log_dir /data/logs/;

listen 80;
server_name nodejs.vicowong.com;

access_log off;
# access_log $log_dir$domain.access.log;
error_log $log_dir$domain.error.log;

root $web_dir;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

nginx 各类网站设置 (laravel , thinkphp , nodejs , https)的更多相关文章

  1. 【转载】网站配置Https证书系列(三):IIS网站设置Http链接直接跳转Https安全连接

    Http链接请求是以明文的方式传输,在传输的过程中很容易被篡改数据,一个典型的例子就是运营商的网络劫持注入广告信息等,而Https请求则是安全加密的请求,报文数据以密文的形式进行传输.当IIS网站配置 ...

  2. Nginx主配置参数详解,Nginx配置网站

    1.Niginx主配置文件参数详解 a.上面博客说了在Linux中安装nginx.博文地址为:http://www.cnblogs.com/hanyinglong/p/5102141.html b.当 ...

  3. 【URLOS应用开发基础】10分钟制作一个nginx静态网站环境应用

    URLOS开发者功能已上线有一段时间了,目前通过部分开发者的使用体验来看,不得不说URLOS在服务器软件开发效率方面确实有着得天独厚的优势,凭借docker容器技术与其良好的应用生态环境,URLOS必 ...

  4. nginx 静态网站配置

    /************************************************************************************** * nginx 静态网站 ...

  5. nginx之旅(第一篇):nginx下载安装、nginx启动与关闭、nginx配置文件详解、nginx默认网站

    一.nginx下载安装 版本nginx 1.15.5 系统环境centos7.5(本机ip192.168.199.228) 关闭selinux 和防火墙firewall 1.下载 wget http: ...

  6. Django+uWSGI+Nginx 部署网站

    Django 1.11设置 保证Django在本地调试没有问题: 当然这是前提^_^ 收集静态文件至指定文件夹 Django静态文件设置具体参考:https://docs.djangoproject. ...

  7. keepalived+nginx+lnmp 网站架构

    <网站架构演变技术研究> 项目实施手册 2019年8月2日 第一章:  实验环境确认 4 1.1-1.系统版本 4 1.1-2.内核参数 4 1.1-3.主机网络参数设置 4 1-1-4 ...

  8. 为何我的网站http总是跳转https?能不能让http不跳转https?谈谈我遇到的坑和解决方案。

    如题,突然想给我的个人网站加一个ssl,让它能够通过https访问. 但一顿操作猛如虎后,发现只能https访问了,手动输入http也会无限跳转到https. 现在说下我的排查思路和解决方案: 1. ...

  9. nginx中如何设置gzip(总结)

    nginx中如何设置gzip(总结) 一.总结 一句话总结: 真正用的时候,花一小点时间把gzip的各个字段的意思都看一下,会节约大量时间 直接gzip on:在nginx的配置中就可以开启gzip压 ...

随机推荐

  1. bug 汇总

    联通营业厅充话费无法在线支付,chrome Python 64位安装包 win7 64 windows 10 右键菜单 Android studio IE11 layout

  2. Python之mmap内存映射模块(大文本处理)说明

    背景: 通常在UNIX下面处理文本文件的方法是sed.awk等shell命令,对于处理大文件受CPU,IO等因素影响,对服务器也有一定的压力.关于sed的说明可以看了解sed的工作原理,本文将介绍通过 ...

  3. Spring mvc时间格式处理

    spring mvc中,如果时间格式是yyyy-MM-dd,传入后台会报错,要增加一些配置才可以. 1.修改spring-mvc.xml,增加org.springframework.format.su ...

  4. windows下nginx安装、配置与使用(转载)

    目前国内各大门户网站已经部署了Nginx,如新浪.网易.腾讯等:国内几个重要的视频分享网站也部署了Nginx,如六房间.酷6等.新近发现Nginx 技术在国内日趋火热,越来越多的网站开始部署Nginx ...

  5. ffmpeg 常用命令

    mp4中的h264编码,而h264有两种封装: 一种是annexb模式,传统模式,有startcode,SPS和PPS是在ES中:另一种是mp4模式,一般mp4.mkv.avi会没有startcode ...

  6. hdu 2191 珍惜现在,感恩生活

    链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191 思路:多重背包模板题 #include <stdio.h> #include ...

  7. Objective-C歌词解析

    #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { FILE* fp1;//定义文件指针 ...

  8. iOS打包ipa给客户测试流程

    IOS项目开发的过程中经常会用到一个测试的问题,特别是外包的项目,客户拿了那么多钱,看不到产品时时的进度说不过去,而且UI和功能是否和符合用户需求这个很重要,需要客户的认同. 所以就需要时时给开发中的 ...

  9. 阿里云CentOS7系列三 -- 配置防火墙

    前面讲到了安装JDK以及Tomcat.但是大家会发现,当我们访问 http:// XXX.XXX.XXX.XXX:8080/80 时候,tomcat 猫并没有出现.原因就是没有设置防火墙. 再次介绍下 ...

  10. python 新手遇到的问题

    作为新手,我把之前遇到的问题贴出来 错误提示1: TypeError: unbound method a() must be called with A instance as first argum ...