Nginx 设置域名转发到指定目录

时间:2024-03-26 09:36:41
  1. 域名转发的其它步骤参见 Nginx 设置域名转发到指定端口
  2. 在指定目录里存放一张图片,以便测试。我这里是在 /www/jaydenmall/ 里存放了一张 gg.jpg
  3. 在 vhost 里添加 image.jaydenmall.com.conf
    sudo vim image.jaydenmall.com.conf
    
    server {
    	listen 80;
    	autoindex off;
    	server_name image.jaydenmall.com;
    	access_log /usr/local/nginx/logs/access.log combined;
    	index index.html index.htm index.jsp index.php;
    	#error_page 404 /404.html;
    	if ( $query_string ~* ".*[\;'\<\>].*" ){
        	return 404;
    	}
    	location ~ /(mall_fe|mall_admin_fe)/dist/view/* {
        	deny all;
    	}
    	location / {
        	root /www/jaydenmall/;
        	add_header Access-Control-Allow-Origin *;
    	}
    }
    
  4. 重启 Nginx
    sudo  ../../sbin/nginx -s reload
    
    Nginx 设置域名转发到指定目录