Jump to content
IPS Community Suite 简体中文
Sign in to follow this  
ipscn

IPS Community Suite Nginx Rewrite Rules

Recommended Posts

本文给出 IPS Community Suite 4.2.6 可用的 Nginx 重写规则。

在 IPS Community Suite 后台,可以直接下载 Apache 的重写规则,但是没有对 Nginx 支持太好,所以,就需要根据自己的情况,写下适用于 Nginx 的重写规则了。

This post will give you a sample about how to config your IPS Community Suite SEO Urls on Nginx .

IPS Community Suite Nginx rewrite rules as following:

server{

    listen 80; #listen end
    server_name 你的域名;
    index index.html index.htm index.php;

    #set $subdomain '';
    #root  /home/wwwroot/html/$subdomain;
    #或者直接写绝对路径
    root  /home/wwwroot/html/你的域名;

    # 包含其它 Nginx 配置,一般是 fastcgi 相关的配置文件
    #include /home/**/other.conf; #rewrite end


    # Set up rewrite rules.
    location / {
        # index  index.php;
        try_files  $uri $uri/ /index.php;
        # 下面的也行
        # try_files $uri $uri/ /index.php?$args;
    }

    location ~^(/page/).*(.php)$ {
        try_files  $uri $uri/ /index.php;
    }

    # Stub Status module
    location /server_status {
        # stub_status on;
        #allow 127.0.0.1;
        #deny all;
    }

   # GZIP static content not processed by IPB.
    gzip  on;
    gzip_static on;
    gzip_http_version 1.1;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_proxied any;
    gzip_types text/plain text/css application/json application/x-javascript application/xml application/xml+rss text/javascript application/javascript text/x-js;
    gzip_buffers 16 8k;
    gzip_disable "MSIE [1-6].(?!.*SV1)";

    # IP.Board PHP/CGI Protection
    location ~^(/uploads/).*(.php)$ {
        deny     all;
    }
    location ~^(/hooks/).*(.php)$ {
        deny     all;
    }
    location ~^(/cache/).*(.php)$ {
        deny     all;
    }
    location ~^(/screenshots/).*(.php)$ {
        deny     all;
    }
    location ~^(/downloads/).*(.php)$ {
        deny     all;
    }
    location ~^(/blog/).*(.php)$ {
        deny     all;
    }
    location ~^(/public/style_).*(.php)$ {
        deny     all;
    }
     # Caching directives for static files.
    location ~^(/uploads/profile/).*.(jpg|jpeg|gif|png)$ {
        access_log off;
        expires    1d;
    }
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|htm|txt|swf|cur)$ {
        access_log off;
        expires    1w;
    }


    #error_page
    error_page 400 /ErrorPages/400.html;
    error_page 403 /ErrorPages/403.html;
    error_page 404 /ErrorPages/404.html;
    error_page 502 /ErrorPages/502.html;
    location ~ /ErrorPages/(400|401|403|404|405|502|503)\.html$
    {
        root /home/wwwroot/lnmp02/domain/bbs/web;
    }

    location ~ .*\.php$
    {
        # 如果你在Ubuntu 或者 LinuxMint 上安装,可能如此
        fastcgi_pass  unix:/run/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fcgi.conf;
        fastcgi_param DOCUMENT_ROOT  /home/wwwroot/html/你的域名;
        fastcgi_param SCRIPT_FILENAME  /home/wwwroot/html/你的域名$subdomain$fastcgi_script_name;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)$
    {
        expires      12h;
    }
        # 不要日志
	access_log off;
	error_log /dev/null;
}

 

按自己的 Nginx 和网站的路径配置,改写下上面的规则,然后在使用 Nginx 检查重写规则后,重载即可。

you may modify the above rules according your Nginx and the directory of your IPS ,then check rules via Nginx, and reload it.

sudo nginx -t
sudo nginx reload

 

下面再提供一个在 Ubuntu 上安装的 IPS 实例的 Nginx 规则:


server {
       # listen 80 default_server;
       # listen [::]:80 default_server;
  
	server_name ips73.com;
	root /var/www/html/ips73.com;
	index index.php  index.html index.htm index.nginx-debian.html;

	client_max_body_size 100M;
	# enforce NO www
	if ($host ~* ^www\.(.*)){
		set $host_without_www $1;
		rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
	}





#########IPS


	location ~ .*\.php$ {
		include /etc/nginx/snippets/fastcgi-php.conf;
		fastcgi_split_path_info  ^(.+\.php)(/.+)$;
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
		include  fastcgi_params;
		fastcgi_param DOCUMENT_ROOT  /var/www/html/ips73.com;
		fastcgi_param SCRIPT_FILENAME  /var/www/html/ips73.com$fastcgi_script_name;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		client_body_timeout      3000;
		fastcgi_read_timeout     3000;
		client_max_body_size     32m;
		fastcgi_buffers 8        128k;
		fastcgi_buffer_size      128k;
		send_timeout             600;
		keepalive_timeout        600;
		proxy_connect_timeout    600;
		proxy_send_timeout       600;
		proxy_read_timeout       600;
        }

	location ~^(/page/).*(.php)$ {
		try_files  $uri $uri/ /index.php;
	}
	location ~^(/uploads/).*(.php)$ {
		deny     all;
	}
	location ~^(/hooks/).*(.php)$ {
		deny     all;
	}
	location ~^(/cache/).*(.php)$ {
		deny     all;
	}
	location ~^(/screenshots/).*(.php)$ {
		deny     all;
	}
	location ~^(/downloads/).*(.php)$ {
		deny     all;
	}
	location ~^(/blog/).*(.php)$ {
		deny     all;
	}
	location ~^(/public/style_).*(.php)$ {
		deny     all;
	}
	# Caching directives for static files.
	location ~^(/uploads/profile/).*.(jpg|jpeg|gif|png)$ {
		access_log off;
		expires    1d;
	}
	location ~* ^.+\.(jpe?g|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|avi|mp3)$ {
		expires 1m;
		access_log off;
		add_header Cache-Control "public";
	}


	#location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|ttf|woff|woff2)$ {
	#expires 1m;
	#access_log off;
	#add_header Cache-Control "public";
	#}
#########IPS//


	# |php
	location ~ \.(aspx|asp|jsp|cgi)$ {
		return 410;
	}

	# CSS and Javascript
	location ~* \.(?:css|js)$ {
		expires 1m;
		access_log off;
		add_header Cache-Control "public";
	}

	# unless the request is for a valid file, send to bootstrap
	if (!-e $request_filename){
		rewrite ^(.+)$ /index.php?q=$1 last;
	}



}

 

 

  • Like 1

Share this post


Link to post

能否具体说下怎么配置重写规则?貌似百度了一下也没看懂

我的LNMP

Share this post


Link to post

server
    {
        listen 888;
        server_name www.bt.cn;
        index index.html index.htm index.php;
        root  /www/server/phpmyadmin;

        #error_page   404   /404.html;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /www/wwwlogs/access.log;
    }
include /www/server/panel/vhost/nginx/*.conf;
}

Share this post


Link to post
cowboy 说:

server
    {
        listen 888;
        server_name www.bt.cn;
        index index.html index.htm index.php;
        root  /www/server/phpmyadmin;

        #error_page   404   /404.html;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /www/wwwlogs/access.log;
    }
include /www/server/panel/vhost/nginx/*.conf;
}

自己的域名,真实的目录。

你这域名,明显不是你的服务器名称,这目录,明显是 phpmyadmin 的。

Share this post


Link to post
ipscn 说:

自己的域名,真实的目录。

你这域名,明显不是你的服务器名称,这目录,明显是 phpmyadmin 的。

请问我该改哪?如何更改??

Share this post


Link to post
ipscn 说:

自己的域名,真实的目录。

你这域名,明显不是你的服务器名称,这目录,明显是 phpmyadmin 的。

server
{
    listen 80 default_server;
	listen 443 ssl default_server;
    server_name bbs.wulal.com;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/bbs.wulal.com;
    
    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /etc/letsencrypt/live/bbs.wulal.com/fullchain.pem;
    ssl_certificate_key    /etc/letsencrypt/live/bbs.wulal.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

    #SSL-END
    
    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    error_page 404 /404.html;
    error_page 502 /502.html;
    #ERROR-PAGE-END
    
    #PHP-INFO-START  PHP引用配置,可以注释或修改
    include enable-php-71.conf;
    #PHP-INFO-END
    
    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/bbs.wulal.com.conf;
    #REWRITE-END
    
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        access_log off; 
    }
    
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        access_log off; 
    }
    access_log  /www/wwwlogs/bbs.wulal.com.log;
}

应该对了吧

Share this post


Link to post

@wqzhshq 在你的 Nginx 的配置目录或者虚拟主机的配置目录,这要看你的运行环境了啊。

  • Thanks 1

Share this post


Link to post

location ~ .*\.php$ {
    	#  try_files $uri $uri/ /index.php?$args;   
	include /etc/nginx/snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
		fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
		# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT  /var/www/html/ips73.com;
fastcgi_param SCRIPT_FILENAME  /var/www/html/ips73.com$fastcgi_script_name;
}

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×