linux下lnmp域名绑定,lnmp安装ngnix配置多域名或多个网站

4e894504a9d4193c034e3787fc84aa22.pngngnix 配置

默认情况下,ngnix下域名的绑定都是通过ngnix.conf文件来配置的,但是有时候我们有多个域名或子域名的情况下要怎么绑定呢?或者有子域名指定不同的目录的时候我们又应该怎么设置呢? 其实很简单,以下就以我的网站为例,很方便就可以进行配置了,如果你们留意看过lnmp一键安装脚本的代码,就知道它的原理。

/usr/local/nginx/conf/nginx.conf

这个是默认的nginx.conf路径,如果你不知道你的nginx安装在哪里,可以通过以下这行代码来查找。

find / -name nginx.conf

打开nginx.conf文件里边的内容是这样的。

user test test;

worker_processes auto;

worker_cpu_affinity auto;

error_log /opt/wwwlogs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.

worker_rlimit_nofile 51200;

events

{

use epoll;

worker_connections 51200;

multi_accept off;

accept_mutex off;

}

http

{

include mime.types;

default_type application/octet-stream;

server_names_hash_bucket_size 128;

client_header_buffer_size 32k;

large_client_header_buffers 4 32k;

client_max_body_size 50m;

sendfile on;

sendfile_max_chunk 512k;

tcp_nopush on;

keepalive_timeout 60;

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 256k;

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;

gzip_vary on;

gzip_proxied expired no-cache no-store private auth;

gzip_disable "MSIE [1-6]\.";

#limit_conn_zone $binary_remote_addr zone=perip:10m;

##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

server_tokens off;

access_log off;

server

{

listen 80 default_server;

#listen [::]:80 default_server ipv6only=on;

server_name _;

index index.html index.htm index.php;

root /opt/www/default;

#error_page 404 /404.html;

# Deny access to PHP files in specific directory

#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

include enable-php.conf;

location /nginx_status

{

stub_status on;

access_log off;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3|mp4|wav)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

location ~ /.well-known {

allow all;

}

location ~ /\.

{

deny all;

}

access_log /opt/wwwlogs/access.log;

}

include vhost/*.conf;

}

这个配置文件里重点是我们要开启以下这一行

include vhost/*.conf;

这一行的意思是读取执行vhost目录下的所有.conf文件,所以我们在vhost目录下新建我们域名的配置文件,可以多个域名一个文件,也可以一个域名一个文件。比如我们就在vhost目录下新建了一个www.myzhenai.com.cn.conf的配置文件。

server

{

listen 80;

listen 443 ssl;

#listen [::]:80;

server_name www.myzhenai.com.cn myzhenai.com.cn;

index index.html index.htm index.php default.html default.htm default.php;

root /opt/www/www.myzhenai.com.cn;

ssl_certificate /usr/local/nginx/cert/www.myzhenai.com.cn.pem;

ssl_certificate_key /usr/local/nginx/cert/www.myzhenai.com.cn.key;

include rewrite/wordpress.conf;

#error_page 404 /404.html;

# Deny access to PHP files in specific directory

#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

include enable-php-pathinfo.conf;

location ~* ^.+\.(gif|jpg|jpeg|png|swf|flv|mp3|mp4|ogg|flav|wav|rar|zip)$ {

valid_referers none blocked www.myzhenai.com.cn;

if ($invalid_referer) {

return 404;

break;

}

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 12h;

}

location ~ /.well-known {

allow all;

}

location ~ /\.

{

deny all;

}

access_log /opt/wwwlogs/www.myzhenai.com.cn.log;

}

这个新建的配置文件里您需要自行修改,因为有些适用,用一些不适用,例如我开启了ssl,所以开启了ssl模块和443端口,我下边就最重要的一些内容做一下简单说明。

listen 80;

listen 443 ssl;

#listen [::]:80;

server_name www.myzhenai.com.cn myzhenai.com.cn;

index index.html index.htm index.php default.html default.htm default.php;

root /opt/www/www.myzhenai.com.cn;

listen 80 #监听80端口

server_name #后面是你的域名或子域名,可以写多个,但指向都是一个目录。

index # 默认文件,即会在网站根目录第一级中打开这些文件中的一个文件,有多个的话会照顺序来打开。

root #这一行是你要指向的网站根目录

配置完conf配置文件后,用以下命令重启ngnix和php

service ngnix restart

service php-fpm restart

sicnature ---------------------------------------------------------------------

Your current IP address is: 49.88.63.53

Your IP address location: 江苏省连云港市电信

Your IP address country and region: 中国

3211c715c0bf352c3fa72980bf0cc419.png

Your current browser is:

b2cb575f9cbd2e36961b3bf406c3355c.png

Your current system is:

mac.png

Original content, please indicate the source:

同福客栈论坛 | 蟒蛇科普 | 海南乡情论坛 | JiaYu Blog

sicnature ---------------------------------------------------------------------

Welcome to reprint. Please indicate the source https://www.myzhenai.com/post/2855.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值