Nginx server配置


項目一般都需要前后端的配置,用二級域名把它區分開:
首先在nginx.conf;里面加一句話:
http{
  #這里面有很多其他的配置 如:gzip FastCGI等等
include vhosts/*.host;
}

文件夾自己定義  反正引進去就好了:

cd yourdirname 創建一個文件 ,命名為:default.host,寫入下面的代碼

server {
  listen 80 default;
  rewrite ^(.*) http://www.xuesong0323.cn permanent;
}

這里創建server的時候  在監聽80端口的后面加了一個default,目的是為了一個默認重定向

每一個二級域名添加進去的時候都推薦新建一個文件,這樣方便以后管理。下面舉個栗子:

文件名:www.host

server {
  listen  80;
  server_name www.xuesong0323.cn;
  
  error_page 404 = http://www.xuesong0323.cn/;
  
  location ~ ^/www/.*\.html$ {
         proxy_redirect off;
    proxy_set_header Host pms.dohohome.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://127.0.0.1:80;
  }
  
  location / {
    root   your root dirname;  #你的項目入口絕對路徑
    index  index.html index.php index.htm;#入口可以解析的文件類型 如果有需要,可以吧index.html/php/htm改成自己需要的文件名和類型
  }
  
  include rewrite/www.conf; #這里我是引入了www的路由重寫規則,具體需要看自己的項目需求  
  
  location ~*\.php$ {
    limit_conn   connlimitzone 15 ;
    limit_req zone=rqlimitzone burst=5 nodelay;
    root           /apps/web/doho/shop_fend/public/; #項目入口絕對路徑
    #try_files $uri=404;
    fastcgi_pass   127.0.0.1:9000;  #php-fpm要用的 不用管
    fastcgi_index  index.php;     #fastcgi_index參數,具體解釋見上一篇
    fastcgi_param  SCRIPT_FILENAME  your root dirname$fastcgi_script_name;
    include        fastcgi_params;
  }

 location ~* .(htaccess)$ {rewrite ^/(.*) /index.php last;}

  access_log  /var/log/nginx/www.access.log  main;  #日志記錄
}

還有一個配置其他端口的:(其實都一樣的)8081.host

server {
        listen       8081;
        server_name  www.xuesong0323.cn;
        #access_log  logs/host.access.log  main;
        location / {
            root   /home/***/;#向配哪里配哪里,后面一致就好了
            index  index.html index.php 1.php 1.html;
        }

        error_page   500 502 503 504  /50x.html;#錯誤頁面
        location = /50x.html {
       #錯誤頁面路徑 root /home/***/
;#這個一般不會改,除非你覺得自己寫的的比較好看= =,我這個是改過的 } location ~ \.php$ { root /home/***/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name; include fastcgi_params; } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM