nginx基本域名

基于域名虚拟主机

[[email protected] nginx]# grep html conf/nginx.conf

root   html;          #docmont  根目录

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;

#    root           html;

#        root   html;

#        index  index.html index.htm;

#        root   html;

#        index  index.html index.htm;

[[email protected] html]# vim index.html

基本于域名的虚拟主机配置

[[email protected] nginx]# tree

.

|-- client_body_temp

|-- conf                       #配置文件目录

|   |-- fastcgi.conf

|   |-- fastcgi.conf.default

|   |-- fastcgi_params

|   |-- fastcgi_params.default

|   |-- koi-utf

|   |-- koi-win

|   |-- mime.types

|   |-- mime.types.default

|   |-- nginx.conf        #主配置文件

|   |-- nginx.conf.default

|   |-- scgi_params

|   |-- scgi_params.default

|   |-- uwsgi_params

|   |-- uwsgi_params.default

|   `-- win-utf

|-- fastcgi_temp

|-- html           #默认站点目录,相当于apache htdocs目录

|   |-- 50x.html     #错误页面

|   `-- index.html  #首页文件

|-- logs   #日志目录

|   |-- access.log

|   |-- error.log

|   `-- nginx.pid

|-- proxy_temp

|-- sbin     #启动目录

|   `-- nginx

|-- scgi_temp

`-- uwsgi_temp

[[email protected] conf]# egrep -v "#|^$" nginx.conf

worker_processes 1;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {                             #相当于apache vhost

listen       80;

server_name  localhost;

location / {

root   html;

index  index.html index.htm;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

[[email protected] conf]# egrep -v "#|^$" nginx.conf >nginx.conf.tmp

[[email protected] conf]# mv nginx.conf.tmp nginx.conf

[[email protected] conf]# cat fastcgi.conf

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param  REDIRECT_STATUS    200

[[email protected] nginx]# vim conf/nginx.conf

user nginx nginx;  #nginx用户名和组

worker_processes  8;   #进程数可以是CPU的数量*2

events {

use epoll;          #事件

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  www.you.com you.com;

location / {

root   /data0/www/www;

index  index.html index.htm;

}

#       error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

[[email protected] conf]# mkdir /data0/www/{www,bbs,blog} -p

[[email protected] conf]# tree /data0/

/data0/

`-- www

|-- bbs

|-- blog

`-- www

4 directories, 0 files

[[email protected] conf]# chown -R nginx.nginx /data0/www

[[email protected] conf]# chown -R nginx.nginx /data0/www

[[email protected] nginx]# ./sbin/nginx -s reload    #平滑启起

基本于多个域名

[[email protected] nginx]# vim conf/nginx.conf

user nginx nginx;

worker_processes  8;

events {

use epoll;

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  www.you.com you.com;

location / {

root   /data0/www/www;

index  index.html index.htm;

}

#       error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

######

server {

listen       80;

server_name  www.bbs.com bbs.com;

location / {

root   /data0/www/bbs;

index  index.html index.htm;

}

#       error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

######

server {

listen       80;

server_name  www.blog.com blog.com;

location / {

root   /data0/www/blog;

index  index.html index.htm;

}

#       error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

}

}

[[email protected] nginx]# ./sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] nginx]# ./sbin/nginx -s reload

加日志

[[email protected] nginx]# mkdir -p /app/logs

[[email protected] nginx]# vim conf/nginx.conf

user nginx nginx;

worker_processes  8;

error_log  /app/logs/nginx_error.log  crit;

pid        logs/nginx.pid;       #加错误日志

events {

use epoll;

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  commonlog  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘"$http_user_agent" "$http_x_forwarded_for"‘;    #正确日志

sendfile        on;

keepalive_timeout  65;

server {

listen       80;

server_name  www.you.com you.com;

location / {

root   /data0/www/www;

index  index.html index.htm;

access_log /app/logs/www_access.log  commonlog;

}

}

######

server {

listen       80;

server_name  www.bbs.com bbs.com;

location / {

root   /data0/www/bbs;

index  index.html index.htm;

access_log /app/logs/bbs_access.log  commonlog;

}

}

######

server {

listen       80;

server_name  www.blog.com blog.com;

location / {

root   /data0/www/blog;

index  index.html index.html;

access_log /app/logs/blog_access.log  commonlog;

}

}

}

service 和配置文件分开

[[email protected] nginx]# mkdir extra

[[email protected] nginx]# cp conf/nginx.conf   extra/nginx_vhosts.conf

主配置文件

[[email protected] nginx]# cat conf/nginx.conf

user nginx nginx;

worker_processes  8;

error_log  /app/logs/nginx_error.log  crit;

pid        logs/nginx.pid;

events {

use epoll;

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  commonlog  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘"$http_user_agent" "$http_x_forwarded_for"‘;

sendfile        on;

keepalive_timeout  65;

include /usr/local/nginx/extra/nginx_vhosts.conf;      #包含虚拟主机的文件,可以包含多个虚拟主机文件

}

虚拟主机配置

[[email protected] nginx]# cat extra/nginx_vhosts.conf

server {

listen       80;

server_name  www.you.com you.com;

location / {

root   /data0/www/www;

index  index.html index.htm;

access_log /app/logs/www_access.log  commonlog;

}

}

######

server {

listen       80;

server_name  www.bbs.com bbs.com;

location / {

root   /data0/www/bbs;

index  index.html index.htm;

access_log /app/logs/bbs_access.log  commonlog;

}

}

######

server {

listen       80;

server_name  www.blog.com blog.com;

location / {

root   /data0/www/blog;

index  index.html index.html;

access_log /app/logs/blog_access.log  commonlog;

}

}

[[email protected] nginx]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[[email protected] nginx]# /usr/local/nginx/sbin/nginx -s reload

时间: 2024-10-29 19:09:15

nginx基本域名的相关文章

WebSocket 结合 Nginx 实现域名及 WSS 协议访问

简单了解一下 WebSocket 现在,很多网站为了实现推送技术,所用的技术都是轮询.轮询是在特定的的时间间隔(如每1秒),由浏览器对服务器发出HTTP请求,然后由服务器返回最新的数据给客户端的浏览器.这种传统的模式带来很明显的缺点,即浏览器需要不断的向服务器发出请求,然而HTTP请求可能包含较长的头部,其中真正有效的数据可能只是很小的一部分,显然这样会浪费很多的带宽等资源.在这种情况下,HTML5定义了WebSocket协议,能更好的节省服务器资源和带宽,并且能够更实时地进行通讯.WebSoc

Nginx二级域名配置

Nginx二级域名配置模板 域名一:www.hellosr.com 域名二:daxin.hellosr.com 通过upstream进行负载均衡,通过access_log的配置规范化请求日志输出 配置如下: #运行用户 #user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processes 2; #全局错误日志及PID文件 #error_log /home/nginx/logs/error.log; #pid /home/nginx/logs/nginx.pi

nginx多域名ssl证书以及lua模块的编译安装

#!/bin/bash #unzip zip&tar file function  untarfile(){ for i in $( ls . |grep -v .sh) do val=$(echo $i | grep ".zip$" |wc -l) if [[ "$val"  -eq  1 ]];then dirname=$(echo $i|sed "s/.zip//") if [[ ! -d $dirname ]];then echo

nginx二级域名配置自动跳转到一级域名

nginx二级域名配置自动跳转到一级域名 rewrite配置内容: if ($http_host !~ "^www.aaa.com$") { rewrite ^(.*) http://www.aaa.com$1 permanent; } 下方,nginx代理访问项目proxy_pass,及rewrite参考 server { listen 80; server_name www.aaa.com 100.100.100.100; location / { if ($http_host !

nginx实现域名重定向

一般网站默认的访问端口为80,当多个域名指向同一个服务器IP时,可以nginx进行重定向,分别指向不同的目的地址或其他主机. 在nginx目录下的conf/vhost子目录下建两个conf文件,host0.conf和host1.conf. host0.conf内容为: server { listen 80; server_name aaa.cn www.aaa.cn; large_client_header_buffers 4 128k; location / { #开启对http1.1支持 p

Nginx 多域名配置

nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里.一.每个域名一个文件的写法       首先打开nginx域名配置文件存放目录:/usr/local/nginx/conf/servers ,如要绑定域名www.itblood.com 则在此目录建一个文件:www.itblood.com.conf然后在此文件中写规则,如: 1 2 3 4 5 6 7 server{     

Nginx中文域名配置

中文域名变为Punycode编码即可,在线转码地址:http://tools.jb51.net/punycode/, Punycode? Punycode是一个根据RFC 3492标准而制定的编码系统,主要用於把域名从地方语言所采用的Unicode编码转换成为可用於DNS系统的编码. "中文域名"后缀不被标准的解析服务器支持,需转化为punycode码进行解析. 修改Nginx配置 server { listen 80; server_name blog.linuxeye.com ;.

nginx做域名转发和uri转发

一. 域名转发 www.qq.com ------> www.baidu.com nginx部署在192.168.1.100,本地配置host 192.168.1.100 www.qq.com ,浏览器输入www.qq.com会跳转到www.baidu.com # vi  /etc/nginx/nginx.conf user nginx;worker_processes 1; events { use epoll; worker_connections 10240; } http { serve

nginx根据域名做http,https分发

omcat端口:8080 做好虚拟主机 参照我的另一篇文章nginx端口:80 根据域名分派 在conf/nginx.conf中的http中增加 include www.huozhe.com.conf 新建conf/www.huozhe.com.conf,内容如下: server {listen 80;server_name www.huozhe.com; location / {    proxy_pass http://127.0.0.1:8080;    proxy_set_header