Nginx configuration

1. Official website: http://nginx.org/en/

2. Chinese document: http://www.nginx.cn/doc/standard/httpupstream.html< /p>

3. Proxy configuration example:

share picture

p>

The configuration is as follows:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/ *.conf;

events {
worker_connections 768;
# multi_accept on;
}

http {
upstream my_server {
server 127.0 .0.1:8001;
}
error_page 404 https://www.baidu.com; #error page
server {
listen 80;
server_name 127.0.0.1;
client_max_body_size 1024M;

location / {
proxy_pass http://my_server/;
proxy_set_header Host $host:$server_port;
}
}

# #
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

i nclude /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1 .1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/ log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/ plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

#mail {< br># # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities “TOP “”USER”;
# # imap_capabilities “IMAP4rev1” “UIDPLUS”;
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on ;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}< br>

4. Problems encountered:

(1). Static files such as js and css cannot be loaded

Because it is a separated project, the The html page uses the $.get(url) method to dynamically load the js file. After using the Nginx reverse proxy, the project path changes, resulting in a 404

share picture

Use “/api/” to proxy “IP: port number”

Want to access http: //bbbb:8080/project name/html/a.html address

You need to visit http://aaaa/api/project name/html/a.html in the browser

At this time, the project path becomes /api/project name/html/a.html

When using the $.get(url) method, there is a problem that the spliced ​​URL address does not exist
< img alt="Share a picture" src="/wp-content/uploads/images/opensource/nginx/1626813724030.png" >

Share a picture

The purpose of the two methods is to access without changing the directory structure, so that the js file can be retrieved by the absolute path

(2), modify the default port of nginx

share picture

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4651 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.