分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 代码编程

nginx+php的配置

发布时间:2023-09-06 01:17责任编辑:傅花花关键词:配置nginx

关闭防火墙 (不然外链接是访问不了 apache) service iptables stop

关闭安全系统 SELinux( 不然报403 访问页面错误 )

1.Nginx安装主要在于配置文件的修改,关联 Nginx与 PHP 。其次是注意要把项目的属组改为nginx用户www:www。

[root@www local]# cat /usr/local/nginx/conf/nginx.conf

user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
?use epoll;
?worker_connections 65535;
}
http
{
?include mime.types;
?default_type application/octet-stream;
?log_format main ?‘$remote_addr - $remote_user [$time_local] "$request" ‘
??????????????‘$status $body_bytes_sent "$http_referer" ‘
??????????????‘"$http_user_agent" $http_x_forwarded_for‘;
?
#charset gb2312;
????
?server_names_hash_bucket_size 128;
?client_header_buffer_size 32k;
?large_client_header_buffers 4 32k;
?client_max_body_size 8m;
????
?sendfile on;
?tcp_nopush on;
?keepalive_timeout 60;
?tcp_nodelay on;
?fastcgi_connect_timeout 300;
?fastcgi_send_timeout 300;
?fastcgi_read_timeout 300;
?fastcgi_buffer_size 64k;
?fastcgi_buffers 4 64k;
?fastcgi_busy_buffers_size 128k;
?fastcgi_temp_file_write_size 128k;
?gzip on;
?gzip_min_length 1k;
?gzip_buffers 4 16k;
?gzip_http_version 1.0;
?gzip_comp_level 2;
?gzip_types text/plain application/x-javascript text/css application/xml;
?gzip_vary on;

?#limit_zone crawler $binary_remote_addr 10m;
#下面是server虚拟主机的配置
server
?{
???#listen 80;#监听端口
???listen 8090;
???#server_name www.mymy.com;#域名
???server_name ?192.168.0.171:8090;
???index index.html index.htm index.php;
???root /usr/local/nginx/html/www;
???include /usr/local/nginx/html/www/.htaccess;
???autoindex off;
# ?????location ~ .*\.(php|php5)?$
# ???{
# ?????#fastcgi_pass unix:/tmp/php-cgi.sock;
# ?????fastcgi_pass 127.0.0.1:9000;
# ?????fastcgi_index index.php;
# ?????include fastcgi.conf;
# ???}

# 关联nginx与php-fpm
location ~ \.php$ {
???????root ??????????/usr/local/nginx/html/www;
???????fastcgi_pass ??127.0.0.1:9000;
???????fastcgi_index ?index.php;
???????fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
???????include ???????fastcgi_params;
}
???location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
???{
?????expires 30d;
?# access_log off;
???}
???location ~ .*\.(js|css)?$
???{
?????expires 15d;
??# access_log off;
???}
???access_log off;
?}

}

nginx开机启动配置:

2.配置nginx开机启动

执行Nginx路径为:/usr/local/nginx/sbin/nginx

Nginx配置文件路径为:/usr/local/nginx/conf/nginx.conf

在/etc/init.d/目录下,cp mysql nginx复制任意一个启动脚本,更名为nginx。并替换为以下内容。并配置开机启动:chkconfig --add nginx ; chkconfig nginx on

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: ??- 85 15
# description: ?NGINX is an HTTP(S) server, HTTP(S) reverse \
# ??????????????proxy and IMAP/POP3 proxy server
# processname: nginx
# config: ?????/etc/nginx/nginx.conf
# config: ?????/etc/sysconfig/nginx
# pidfile: ????/var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
??# make required directories
??user=`$nginx -V 2>&1 | grep "configure arguments:" | sed ‘s/[^*]*--user=\([^ ]*\).*/\1/g‘ -`
??if [ -z "`grep $user /etc/passwd`" ]; then
??????useradd -M -s /bin/nologin $user
??fi
??options=`$nginx -V 2>&1 | grep ‘configure arguments:‘`
??for opt in $options; do
??????if [ `echo $opt | grep ‘.*-temp-path‘` ]; then
??????????value=`echo $opt | cut -d "=" -f 2`
??????????if [ ! -d "$value" ]; then
??????????????# echo "creating" $value
??????????????mkdir -p $value && chown -R $user $value
??????????fi
??????fi
??done
}
start() {
???[ -x $nginx ] || exit 5
???[ -f $NGINX_CONF_FILE ] || exit 6
???make_dirs
???echo -n $"Starting $prog: "
???daemon $nginx -c $NGINX_CONF_FILE
???retval=$?
???echo
???[ $retval -eq 0 ] && touch $lockfile
???return $retval
}
stop() {
???echo -n $"Stopping $prog: "
???killproc $prog -QUIT
???retval=$?
???echo
???[ $retval -eq 0 ] && rm -f $lockfile
???return $retval
}
restart() {
???configtest || return $?
???stop
???sleep 1
???start
}
reload() {
???configtest || return $?
???echo -n $"Reloading $prog: "
???killproc $nginx -HUP
???RETVAL=$?
???echo
}
force_reload() {
???restart
}
configtest() {
?$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
???status $prog
}
rh_status_q() {
???rh_status >/dev/null 2>&1
}
case "$1" in
???start)
???????rh_status_q && exit 0
???????$1
???????;;
???stop)
???????rh_status_q || exit 0
???????$1
???????;;
???restart|configtest)
???????$1
???????;;
???reload)
???????rh_status_q || exit 7
???????$1
???????;;
???force-reload)
???????force_reload
???????;;
???status)
???????rh_status
???????;;
???condrestart|try-restart)
???????rh_status_q || exit 0
???????????;;
???*)
???????echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
???????exit 2
esac

nginx+php的配置

原文地址:http://www.cnblogs.com/sherman125/p/7672595.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved