分享好友 编程语言首页 频道列表

nginx 各类网站设置 (laravel , thinkphp , nodejs , https)

nodejs文章/教程  2023-02-09 05:360

基础部分设置

[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;
}
}

 

查看更多关于【nodejs文章/教程】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
打造自己的 nodejs 静态文件服务器(帖子内容,直接复制别人的)
用NodeJS打造你的静态文件服务器在《The Node Beginner Book》的中文版(http://nodebeginner.org/index-zh-cn.html)发布之后,获得国内的好评。也有同学觉得这本书略薄,没有包含进阶式的例子。@otakustay同学说:“确实,我的想法是在这之上补一个简单的MV

0评论2023-02-10548

NodeJS无所不能:细数10个令人惊讶的NodeJS开源项目
在几年的时间里,NodeJS逐渐发展成一个成熟的开发平台,吸引了许多开发者。有许多大型高流量网站都采用NodeJS进行开发,像PayPal,此外,开发人员还可以使用它来开发一些快速移动Web框架。  除了Web应用外,NodeJS也被应用在许多方面,本文盘点了NodeJS在其

0评论2023-02-10598

Linux环境下的Nodejs linux安装基本环境
最近在学习Node.js,在window下总是觉得不那么爽快。最简单而且环保的方法是在虚拟机中安装一个Linux。 { 1.Linux:家中的Linux为Centos。 2.VirtuallyBox: 开启2块网卡。第一个选Host-Only目的是为了让虚拟机通上网。第二块选Bridge Adapter,这是为了

0评论2023-02-09597

nodejs package.json说明
{"name": "test", //项目名称(必须),由小写英文字母、数字和下划线,不能含空格"version": "1.0.0", //项目版本(必须)"description": "This is for study gulp project !", //项目描述(必须)"homepage": "", //项目主页url " key

0评论2023-02-09473

017 nodejs取参四种方法req.body,req.params,req.param,req.body
摘要: nodejs取参四种方法req.body,req.params,req.param,req.body 获取请求很中的参数是每个web后台处理的必经之路,nodejs提供了四种方法来实现。获取请求很中的参数是每个web后台处理的必经之路,nodejs的 express框架 提供了四种方法来实现。req.bodyre

0评论2023-02-09446

nodejs查看本机hosts文件域名对应ip
const dns = require('dns')dns.lookup('domainName', function(err, result) {console.log(result)}) related:https://***.com/questions/36689536/how-to-resolve-hostname-to-an-ip-address-in-node-js

0评论2023-02-09475

nodejs工程拷贝后运行报module找不到问题
工程文件夹通过复制黏贴到另外一个地方,运行后报错 “can`t find module 某某某”,查看原因:输入node 进入控制台,输入console.log(module.paths)查看当前nodejs查找module的路径,如果没有工程里的node_modules,通过module.paths.push加入,检查是否有效

0评论2023-02-09947

C# Socket TCP Server & Client & nodejs client cctv5体育节目表
要调试公司某项目里的一个功能,因为要准备测试环境,趁这个机会重温了一下Socket(全还给老师了 -_-#),做个备份。C# Serverstatic void Main(string[] args){int port = 81;string host = "192.168.1.151";//创建终结点IPAddress ip = IPAddress.Parse(hos

0评论2023-02-09810

nodejs微信公众号快速开发|自定义关键字回复
一点说明:nodejs 微信api 扩展,集成大部分功能。案例https://github.com/leiroc/node-wxeasy-example 上传example中文件到服务器 ,然后 npm install 成功https://github.com/leiroc/node-wxeasy-exampleBUG and NEWS增加客户功能增加模板消息增加扫描带参数

0评论2023-02-09404

Centos 32位 安装 NodeJS
yum -y install gcc make gcc-c++ openssl-devel wget下载源码及解压:wget https://nodejs.org/dist/v6.9.5/node-v6.9.5.tar.gztar -zvxf node-v0.10.26.tar.gz编译及安装:cd node-v0.10.26 切换目录,执行./configuremakemake install验证是否安装配置成功

0评论2023-02-09537

nodejs一部分基本模块及作用 node 引入一个模块的过程是什么
收集了NodeJS开发中常用的一些模块。MVC框架 -ExpressExpress 是轻量灵活的Nodejs Web应用框架,它可以快速地搭建网站。Express框架建立在Nodejs内置的Http模块上,并对Http模块再包装,从而实际Web请求处理的功能。它支持多种前端模板,如Jade, EJS等。它是T

0评论2023-02-09868

nodejs定时启动程序 nodejs开机自启
npm install node-schedule# 或yarn add node-schedule使用(second、minute、hour、  date、dayOfWeek、month、year)每分钟第1秒执行一次const schedule = require("node-schedule");var rule = new schedule.RecurrenceRule();rule.second = 1;// 秒schedu

0评论2023-02-09406

更多推荐