❶ nginx同域名配置多目录路径
server{
server_name xxx.cn;
charset utf-8;
location / {
index index.html index.shtml;
root /web/t; 新路径
error_page 404 = @not_found;
}
location @not_found {
index index.html index.shtml;
root /web1/t; 老路径
}
}
❷ 配置服务器 —— Nginx添加多个二级子域名 --- 2018-06-26
Nginx多文件配置二级子域名(推荐)
首先,在自己的域名控制台中添加解析,这里以添加blog前缀为例
我用的是万网,在 解析设置 中 添加解析
主机记录 :你想要的二级域名
记录值 :你的IP地址
保存后,我们就完成了第一步把子域名解析到我们的服务器上。
第二步:添加配置文件
进入nginx的 /conf 配置文件夹中,编辑 nginx.conf 文件
[root@iZ2844brz0xZ~]# cd /usr/local/nginx/conf/[root@iZ2844brz0xZ~]# vim nginx.conf
在 http 模块中添加如下语句
include/usr/local/nginx/conf/sites-enabled/*.conf;
告诉这个配置文件要去包含 /sites-enabled 目录下的所有以 .conf 结尾的配置文件。:wq 保存。
此时,我们新建一个 /sites-enabled 文件夹,并在其中添加 blog.***.com.conf 文件
[root@iZ2844brz0xZconf]# mkdir sites-enabled[root@iZ2844brz0xZsites-enabled]# vim blog.***.com.conf
在文件中添加
server {listen80;#监听端口server_name blog.***.com;#绑定域名root /usr/local/nginx/html/blog/;#网站根目录,建议使用绝对路径indexindex.phpindex.htmlindex.htm;#默认文件#添加对php的解析location ~ \.php$ { fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name; include /usr/local/nginx/conf/fastcgi_params; }#添加错误页面,利于搜索引擎收录以及良好的用户体验error_page404/404.html; location /404.html { root /usr/local/nginx/html/; } error_page500502503504/50x.html; location =/50x.html {
root /usr/local/nginx/html/; }}
内容可自行添加
Nginx单文件配置二级子域名
在 nginx.conf 文件的 server 模块中添加以下语句
if($host~* (\b(?!www\b)\w+)\.\w+\.\w+ ) { set$subdomain/$1;}location / { root html$subdomain;indexindex.htmlindex.phpindex.htmindex;}
即可解析到对应文件夹
最后,重启nginx即可
[root@iZ2844brz0xZsites-enabled]# /usr/local/nginx/sbin/nginx -s reload
来自:https://blog.csdn.net/LBinin/article/details/70188752
❸ nginx命令如何把多个文件压缩到一个文件夹
目前应该是做不到,有一个顺序的,比如乌鸦喝水,要想喝到水,必须把东西放进瓶子了,然后水就满上来,只有满上来,才可以喝到水,你也一样,竟然都是压缩文件,你可以将压缩包全部选中,记住是压缩包,不能是别的文件,选择以后进行解压到当前的目录,这样的话,大部分的图片会呈现在我们的目录下,也许有些压缩包里面还有根目录,创建文件夹,利用索引图片格式,把所有的图片放你创建的文件下,然后对有根目录的文件进行二次处理,这样会好一下,目前我只能想这样的解决方案,毕竟我不能够保证你某个压缩包下的文件目录级别是几个,如果都是同一级的目录,就好解决了,希望方案能够给你解决问题
❹ Nginx 使用多个.conf文件配置多个虚拟主机server的方法
一般Nginx的配置都默认在 /usr/local/etc/nginx/nginx.conf 里,但是如果我们有多个虚拟主机需要配置的话,全部写在 nginx.conf 下会很臃肿,因此呢, Nginx 提供 include 包含其他配置文件的方式帮助我们解决这个问题,接下来我们就来看看具体怎么配置
安装好 Nginx 后,其默认配置文件不需要更改,它已经帮我们导入了其他配置文件的目录,如上图,最后一句 include servers/*; ,意思就是该配置文件包含 nginx.conf 的同级目录下的 servers 文件夹下所有的文件,这时候我们只需要在 nginx.conf 的同级目录下创建一个 servers 的文件夹,然后创建自己的 .conf 文件就行,当然,如果你的配置文件是其他目录,就修改 include 后的路径就可以
xxx.conf 中的只需要写 server 块就行,其实就相当于把这个 server 块添加到 nginx.conf 中的 http 块中
重启 nginx
sudo nginx -s reload
❺ nginx部署多个前后端项目
http://127.0.0.1/helloworld 第一个vue项目(不用修改配置直接build就可以)
http:// 127.0.0.1 /test02 第二个vue项目(需要修改)
1、首先在config文件夹内的index.js内修改(注意是build内)
build: {
// Template for index.html
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
//nginx配置
assetsPublicPath: '/test2/',
/**
* Source Maps
*/
proctionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#proction
devtool: '#source-map',
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
proctionGzip: false,
proctionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}
2、这样确保生产出来的文件,在index.html中都是在student下。对index.html文件进行修改,添加base href="/test2/" >
<!DOCTYPE html>
<html>
<head>
<!--新添加的-->
<base href="/test2/" >
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<title>test1</title>
<link href=/test2/static/css/app..css rel=stylesheet>
</head>
<body>
<div id=app></div>
<script type=text/javascript src=/test2/static/js/manifest.a96262ba9edf9a4c5761.js></script>
<script type=text/javascript src=/test2/static/js/vendor.a6129cab87d1dbebc84c.js></script>
<script type=text/javascript src=/test2/static/js/app.4694a2e388440c566511.js></script>
</body>
</html>
3、在src/router/index.js文件修改,添加 base: '/test2/'
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
Vue.use(Router)
export default new Router({
base:"/test2/",
mode:"history",
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
}
]
})
user root;
worker_processes 1; #nginx进程个数
#worker_cpu_affinity 1000 0100 0010 0001; #绑定worker进程到指定的CPU内核中
#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; #worker进程的最大连接数是1024
}
http {
#include mime.types;
# include /etc/nginx/conf.d/*.conf;
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;
upstream rest{
least_conn;
server 127.0.0.1:8000;
server 127.0.0.1:8001;
}
#gzip on;
server {
listen 80;
server_name 127.0.0.1;
#charset koi8-r;
#access_log logs/host.access.log main;
#vue第一个项目
location / {
root /usr/local/nginx/projects/dist;
try_files $uri $uri/ @router;
index index.html index.htm;
}
#vue第二个项目
location /test2 {
alias /usr/local/nginx/projects/test2/;
try_files $uri $uri/ /test2/index.html;
index index.html index.htm;
}
location @router {
rewrite ^.*$ /index.html last;
}
#vue第一个项目后端接口
location /api_a {
#转发到后端uwsgi
proxy_pass http://127.0.0.1:5002;
# 设置请求头,并将头信息传递给服务器端
proxy_set_header Host $host;
# 设置请求头,传递原始请求ip给 gunicorn 服务器
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#
}
#vue第二个项目后端接口
location /api_b {
#转发到后端uwsgi
proxy_pass http://127.0.0.1:5003;
# 设置请求头,并将头信息传递给服务器端
proxy_set_header Host $host;
# 设置请求头,传递原始请求ip给 gunicorn 服务器
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#
}
#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;
}
}
}
❻ 5,nginx 多域名,配置多个conf 文件
nginx下配置多域名,目前的配置方法采用多个配置文件的方法比较多
1,在nginx安装的目录下找到, nginx.conf文件
如我的: C:\Program Files\nginx-1.15.5\conf 目录下
2,在该目录下创建的文件夹,如 vhost 文件夹
C:\Program Files\nginx-1.15.5\conf\vhost
3,在vhost 文件夹下创建 *.conf 文件 如host.conf
C:\Program Files\nginx-1.15.5\conf\vhost\host.conf
4,编辑conf文件,把我们平常放在nginx.conf里的server{......}段直接粘贴到conf里。
如:
5,最后在nginx.conf的http{....}段中加入
include vhost/*.conf;
6,如果有其他的conf文件要添加直接在 按照步骤三操作即可
❼ nginx根目录设置到其他文件夹
nginx服务器绑定域名以及设置根目录非常方便,首先进入nginx安装目录,然后执行 vim conf/nginx.conf 打开nginx的配置文件,找到
server {
.....
}
这个代码段,这段代码就是用来配置对应站点的,首先我们应该在域名控制面板将域名解析到我们服务器的IP地址,然后绑定才可以生效。《linux就该这么学》一起学习linux
首先在我们的代码段中找到server_name这一项然后把后面的域名改成我们要绑定的域名即可
root这一项就是指定的根目录,设置成我们指定的目录即可.
上配置:
server {
listen 80;
server_name localhost;
root /.../tomcat*/../ ; # 设置root目录 运行nginx的用户有权限。
location / {
index index.html index.htm;
}
}