nginx模板
vim nginx/conf/nginx.conf
#user nobody;
worker_processes 1; #进程数
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024; #并发连接数
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server { #一个server代表一个网站
listen 80;
server_name localhost; #域名
auth_basic "input here:";
auth_basic_user_file "/usr/local/nginx/pass";
#charset koi8-r;
#access_log logs/host.access.log main;
location / { #网站路径
root html; #网站相对路径下./nginx/html/
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
访问页面时添加限制用户
http {
server {
listen 80;
server_name localhost;
auth_basic "input here"; #提示语
auth_basic_user_file "/usr/local/nginx/pass"; #账户密码保持位置
}
}
创建密码文件
yum -y install httpd-tools
#创建用户
[root@host1 nginx]# htpasswd -c /usr/local/nginx/pass tom
New password:
Re-type new password:
Adding password for user tom
#追加用户:
[root@host1 nginx]# htpasswd /usr/local/nginx/pass alice
New password:
Re-type new password:
Adding password for user alice
vim快捷选中
ESC模式下,ctrl+v 选中,然后d删除
基于域名的网站访问
http{
server{
listen 80;
server_name www.a.com;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.b.com;
location / {
root www;
index index.html index.htm;
}
}
}
基于IP的网站访问
http{
server {
listen 192.168.168.51:80;
server_name www.a.com;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 192.168.168.52:80;
server_name www.a.com;
location / {
root www;
index index.html index.htm;
}
}
}
基于端口的网站访问
http {
server {
listen 80;
server_name localhost;
localtion / {
root html;
index index.html index.htm;
}
}
server {
listen 8000;
server_name localhost;
localtion / {
root www;
index index.html index.htm;
}
}
}
加密:公私钥
生产公钥
openssl genrsa > cert.key #genrsa生产rsa私钥
openssl req -new -x509 -key cert.key > cert.pem
#请求生产一个新的x509格式的证书(公钥)
SSL加密
server {
listen 443 ssl;
server_name www.c.com;
ssl_certificate cert.pem; #在相对路径下./conf下
ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
php参数详解
vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000 #PHP端口号
pm.max_children = 32 #最大进程数量
pm.start_servers = 15 #最小进程数量
pm.min_spare_servers = 5 #最少需要几个空闲进程
pm.max_spare_servers = 32 #最多需要几个空闲进程
nginx+php动态页面配置
location ~ \.php$ { # "~" 扩展正则,\.php$ 匹配php结尾 "\.":屏蔽".","."任意符合
root html; #页面路径
fastcgi_pass 127.0.0.1:9000; #将请求交给(pass) PHP:9000
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #这行原本有误,需注释
include fastcgi.conf; #include 加载其他配置
}
在apache中配置文件中
/etc/httpd/conf/httpd.conf
include conf.d/*.conf #include加载其他配置
/etc/httpd/conf.d/xx.conf
地址重写1:页面跳转
格式:rewrite 旧地址 新地址 选项
插播:通过浏览器访问域名,转向到另外一个网站,
跳转后,浏览器地址还是该域名,称为隐形url转发,
跳转后,浏览器地址变成新的域名,则为显形url转发
http {
server {
...
charset utf-8; #该网站的编码
location / {
root html;
index index.html index.htm;
rewrite /a.html /b.html; #地址重写,隐形url
rewrite /a.html /b.html redirect; #地址栏也跳转到b.html,显形url
}
}
}
last 匹配及停止,不再读其他的rewrite
break 不再读其他语句,结束请求,比last强烈
redirect 临时重定向(地址栏会变)
permament 永久重定向(地址栏会变)
地址重写2:域名跳转
http {
server {
listen 80;
server_name localhost/www.a.com..; #地址栏可以是IP或域名
rewrite ^/ http://www.baidu.com/; #必须加http,否则不能识别跳转 #"^/" 代表匹配所有,在浏览器中输入时自动匹配跳转到百度首页
rewrite ^/(.*) http://www.tmooc/$1; #正则,跳转到指定的输入地址。例如:..51/xxx --> baidu.com/xxx
#shell正则语法格式为:/(.*)(.*) \1\2.nginx则为/$1/$2
#pcre-devel 扩展正则
location / {
root html;
index ...;
}
}
}
255

被折叠的 条评论
为什么被折叠?



