nginx 搭建靜態服務器 文件服務器 端口轉發 nginx.conf配置

部署靜態網站

將靜態網站複製到nginx路徑下的html文件夾下(其他路徑也可以的,可以寫絕對路徑)
在http{sever{ 填寫下方代碼}}

 location / {
            root   html/birthday/;
            index  index.html;
        }

html/birthday/ 相對地址 nginx/html部署birthday的靜態網頁,也可以寫絕對路徑
查看 http://localhost

搭建文件服務器

創建/html/file/文件夾

sudo mkdir /html/file

將文件上傳到/html/file中
設置文件夾的訪問權限

chmod 754 -R /html/file

修改/etc/nginx/nginx.conf文件

location /file  {
            alias  /html/file/;
	          autoindex  on;
        }

查看http://ip地址:端口/file/
如果瀏覽器查看文件名時,中文名亂碼
修改/etc/nginx/nginx.conf 中 server 後添加charset utf-8;

window 上傳到linux服務器文件亂碼

apt install convmv
convmv -f gbk -t utf-8 --notest -r ./ 

端口轉發

location /video  {
	    proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	    proxy_pass http://118.178.195.62:8080/;
        }	

proxy_pass http://118.178.195.62:8080/;關鍵是這句話

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章