current position:Home>Nginx - configuration file

Nginx - configuration file

2022-01-27 02:14:35 Carrot rabbit

nginx Configuration structure diagram
 Insert picture description here

nginx Master profile

# to nginx Users and user groups 
user  nginx nginx;
# worker  often   Automatically   Automatically start the process as needed 
worker_processes  auto;
#nginx Wrong day 
error_log  /var/log/nginx/error.log notice;
# Maximum number of process connections   Default 1024
events {
    
    worker_connections  1024;
}


http {
    
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    # Maximum timeout  65s
    keepalive_timeout  65;
    # Include subsite configuration 
    include /usr/local/nginx/conf/conf.d/*.conf;

}

nginx Subsite configuration

server {
    
    listen       80;
    server_name  shop.xxx.com;
    #  Pseudostatic 
 	rewrite ^/(.*)\.html$ /$1.php;
    #access_log /var/log/nginx/host.access.log main;

    location / {
    
		# Here's the solution nginx The cross domain problem in this paper 
        add_header Access-Control-Allow-Origin *;
 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
 add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
 if ($request_method = 'OPTIONS'){
    
 return 204;
 }
        root   /usr/share/nginx/html/shop;
        index  index.php index.html index.htm;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    
        root   /usr/share/nginx/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(.*)$ {
    
    # php Source file directory 
        root            /usr/share/nginx/html/shop;
        #nginx  adopt 9000  port   hold php File to  php-fpm  analysis 
        fastcgi_pass   127.0.0.1:9000; 
        #  This is the default file for parsing 
        fastcgi_index  index.php;
        #pathinfo Pattern 
        fastcgi_split_path_info  ^(.*\.php)(.*)$;
        #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
        # Pass the reference to php-fpm
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;

        include        fastcgi_params;

    }

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

copyright notice
author[Carrot rabbit],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270214328317.html

Random recommended