nginx 搭建静态网页服务,不同的前缀进入不同的静态文件路径详解程序员

 
server { 
            listen 5555 default_server; 
  listen [::]:5555 default_server; 
    server_name _; 
 
        proxy_set_header X-Forwarded-Host $http_host; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Forwarded-Proto $scheme; 
        proxy_set_header X-Real-IP $remote_addr; 
 
        # rewrite ^(.*)$ https://www.odoo.com/; 
            location / { 
                root /root/workspace/build; # 设置静态文件所在的根目录 
                autoindex on; 
                autoindex_exact_size off; 
                autoindex_localtime on; 
     # proxy_pass https://www.odoo.com/; 
                # proxy_pass http://kk2w.cc/; 
                proxy_set_header X-Forwarded-Host $http_host; 
                proxy_set_header X-Real-IP $remote_addr; 
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                client_max_body_size 20m; 
 
  } 
 
} 
 

使用不同的url前缀来访问不同的文件路径,我的配置文件如下:

注意根路径需要使用alias 而不是 root

server { 
	listen 8888 default_server; 
  	listen [::]:8888 default_server; 
    	server_name odoo.abc.xyz; 
 
        proxy_set_header X-Forwarded-Host $http_host; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header X-Forwarded-Proto $scheme; 
        proxy_set_header X-Real-IP $remote_addr; 
 
	# rewrite ^(.*)$ https://www.odoo.com/; 
	location /odoo14/ { 
		alias /root/workspace/odoo14/build/; 
		autoindex on; 
		autoindex_exact_size off; 
		autoindex_localtime on; 
		 proxy_set_header X-Forwarded-Host $http_host; 
                 proxy_set_header X-Real-IP $remote_addr; 
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                 client_max_body_size 20m; 
 
	} 
	    location /odoo12/ { 
		alias /root/workspace/build/; 
		autoindex on; 
		autoindex_exact_size off; 
		autoindex_localtime on; 
	     # proxy_pass https://www.odoo.com/; 
    		# proxy_pass http://kk2w.cc/; 
                proxy_set_header X-Forwarded-Host $http_host; 
                proxy_set_header X-Real-IP $remote_addr; 
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
                client_max_body_size 20m; 
 
  } 
 
} 

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/1606.html

(0)
上一篇 2021年7月15日
下一篇 2021年7月15日

相关推荐

发表回复

登录后才能评论