debian9.9 nginx 与discuz 集成配置

后端 0 841
小小草
小小草 2020年6月28日 13:30 发表
摘要:之前使用了apache2 作为discuz软件服务器,昨天计划换成nginx,配置虽然简单,昨晚这么了一宿,这里做下说明,以备不时之需 操作步骤 1、这里使用监听方式配置,顾在配置之前请确认安装了php-fpm模块,具体安装方法

之前使用了apache2 作为discuz软件服务器,昨天计划换成nginx,配置虽然简单,昨晚这么了一宿,这里做下说明,以备不时之需


操作步骤
1、这里使用监听方式配置,顾在配置之前请确认安装了php-fpm模块,具体安装方法,参见; php-fpm模块安装指导  

2、找到nginx 配置文件
注意我这里luntan-debian.conf已提前引入到nginx中,在此不做说明


完整文件配置:

server {
listen 80;
server_name 106.122.207.12;
root /var/www/html;
#charset koi8-r;

#access_log logs/host.access.log main;



index index.html index.htm index.php;


#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;


# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

location ~ \.php$ {
root /var/www/html;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}

location ~ \.do$ {
proxy_pass http://localhost:8080;#转发给tomcat端口,也可以是任何server。
proxy_set_header X-Real-IP $remote_addr;#转发客户端真实IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location ~ \.jsp$ {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

location ~ ^/servlet/* {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

location ~ ^/imageServlet/* {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}


location ~ ^/static/* {
add_header content-type "text/html;charset=UTF-8";
root /var/www/html;

}


#所有静态文件由nginx直接读取不经过tomcat或resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{
expires 1d;
}

#location ~ .*.(js|css)?$
#{
# root /var/www/html;
# expires 1h;
#}


}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}



3、具体配置如下:luntan-debian.conf

location ~ \.php$ {

root /var/www/html;

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;

fastcgi_param QUERY_STRING $query_string;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

}

简单说明:

/var/www/html discuz安装目录

/run/php/php7.0-fpm.sock php-fpm监控目录,可以在此配置文件中/etc/php/7.0/fpm/php-fpm.conf找到

fastcgi_index index.php; 注意这个必须配置,否则首页无法进入

附php-fpm.conf截图

点赞 0 收藏(0)    分享
相关标签: php
问题没解决?让chatGPT帮你作答 智能助手
0 个评论
  • 消灭零评论